-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
155 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,100 @@ | ||
# Git Cheatsheet | ||
|
||
##### Commands - Git Basics | ||
## Git Basics | ||
|
||
``` | ||
$ git --version // Displays version of Git installed | ||
$ git init // Initialize the current folder as a git repository | ||
$ git init <directory> // Initialize the directory specified as a git repository | ||
$ git clone <repo-url/path> // Clone an existing remote repo or local repo onto local machine | ||
$ git status // List which files are staged, unstaged and untracked | ||
$ git add <directory> // Stage all changes in directory for the next commit | ||
$ git commit -m "<message>" // Commit the staged snapshot with <message> as commit message | ||
$ git commit --amend // Update last commit message | ||
$ git log // Display the entire commit history using default format. (customize) | ||
$ git diff // Show unstaged changes between your index and working directory. | ||
$ git diff HEAD // Show difference between working directory and last commit | ||
$ git diff --cached // Show difference between staged changes and last commit | ||
``` | ||
```sh | ||
# Displays version of Git installed | ||
$ git --version | ||
|
||
##### Commands - Undoing Changes | ||
# Initialize the current folder or directory as a git repository | ||
$ git init | ||
$ git init <directory> | ||
|
||
``` | ||
$ git revert <commit> // Create new commit that undoes all of the changes made in <commit>, then apply | ||
$ git reset // Reset staging area to match most recent commit, but leave code unchanged | ||
$ git reset <file> // Remove <file> from staging area | ||
$ git reset --hard // Reset staging area and working directory | ||
$ git reset <commit> // Move current branch tip backward to <commit>, reset staging area but NOT local code | ||
$ git reset --hard <commit> // Move current branch tip backward to <commit>, reset staging area as well as local code | ||
$ git clean -n // ------- read more | ||
``` | ||
# Clone an existing remote repo or local repo onto local machine | ||
$ git clone <repo-url/path> | ||
|
||
##### Commands - Git Branches | ||
# List which files are staged, unstaged and untracked | ||
$ git status | ||
|
||
``` | ||
$ git branch // List all of the branches in your repo | ||
$ git checkout <branch> // Checkout an existing branch named <branch> | ||
$ git checkout -b <branch> // Create and checkout a new branch named <branch> | ||
$ git merge <branch> // Merge <branch> into current branch | ||
``` | ||
# Stage all changes in directory for the next commit | ||
# Will only add new files and modified files to the index to be committed | ||
$ git add <directory> | ||
# Stage all changes in the repository | ||
$ git add -A | ||
|
||
##### Commands - Remote Repositories | ||
# Commit the staged snapshot with <message> as commit message | ||
$ git commit -m "<message>" | ||
|
||
# Update last commit message | ||
$ git commit --amend | ||
|
||
# Display the entire commit history using default format. | ||
$ git log | ||
|
||
# Show unstaged changes between your index and working directory | ||
$ git diff | ||
# Show difference between working directory and last commit | ||
$ git diff HEAD | ||
# Show difference between staged changes and last commit | ||
$ git diff --cached | ||
``` | ||
$ git remote add <name> <url> // Create a new connection to remote repo. <name> is shortcut for <url> | ||
$ git remote set-url <name> <url> // Update the remote repo url to <url> with shortcut <name> | ||
$ git fetch <remote> <branch> // Fetches a specific <branch> from the remote repo. | ||
$ git pull <remote> // Fetch the specified remote's copy of current branch and merge into local copy | ||
$ git push <remote> <branch> // Push the <branch> to <remote>, along with necessary commits and objects. | ||
// Creates named branch in remote if doesn't exist | ||
|
||
## Undoing Changes | ||
|
||
```sh | ||
# Create new commit that undoes all of the changes made in <commit>, then apply | ||
$ git revert <commit> | ||
|
||
# Reset staging area to match most recent commit, but leave code unchanged | ||
$ git reset | ||
# Remove <file> from staging area | ||
$ git reset <file> | ||
# Reset staging area and working directory | ||
$ git reset --hard | ||
# Move current branch tip backward to <commit>, reset staging area but NOT local code | ||
$ git reset <commit> | ||
# Move current branch tip backward to <commit>, reset staging area as well as local code | ||
$ git reset --hard <commit> | ||
|
||
# Remove untracked files from your working directory | ||
$ git clean | ||
# Perform a "dry run" of the git clean | ||
# Shows what files would be removed from the working directory, but it won't actually remove them. | ||
$ git clean -n | ||
``` | ||
|
||
##### Note | ||
## Git Branches | ||
|
||
```sh | ||
# List all of the branches in your repo | ||
$ git branch | ||
|
||
# Checkout an existing branch named <branch> | ||
$ git checkout <branch> | ||
|
||
# Create and checkout a new branch named <branch> | ||
$ git checkout -b <branch> | ||
|
||
# Merge <branch> into current branch | ||
$ git merge <branch> | ||
``` | ||
$ git add . // Will only add new files and modified files to the index to be committed | ||
$ git add -A // Will do everything + also schedule removed files for deletion | ||
|
||
## Remote Repositories | ||
|
||
```sh | ||
# Create a new connection to remote repo. <name> is shortcut for <url> | ||
$ git remote add <name> <url> | ||
|
||
# Update the remote repo url to <url> with shortcut <name> | ||
$ git remote set-url <name> <url> | ||
|
||
# Fetches a specific <branch> from the remote repo. | ||
$ git fetch <remote> <branch> | ||
|
||
# Fetch the specified remote's copy of current branch and merge into local copy | ||
$ git pull <remote> | ||
|
||
# Push the <branch> to <remote>, along with necessary commits and objects | ||
$ git push <remote> <branch> | ||
#Creates named branch in remote if doesn't exist | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters