Appearance
Git Cheat Sheet
1. Setup
Configuring global information
git config —global user.name “[firstname lastname]”
Sets your name for all commits, so you get credit when viewing version history.git config —global user.email “[valid-email]”
Sets your email address to be used in commit history.
2. Stage & Snapshot
Working with Snapshots and the Git Staging Area
git status
Shows the modified files in your working directory and which files are staged for the next commit.git add [file]
Adds a file to the staging area (getting it ready for the next commit).git reset [file]
Removes a file from the staging area but keeps the changes in the working directory.git diff
Shows the changes in your working directory that are not yet staged.git diff —staged
Shows the changes that are staged but not yet committed.git commit -m “[descriptive message]”
Commits your staged changes with a descriptive message.
3. Branch & Merge
Isolating Work in Branches and Merging Changes
git branch
Lists all your branches. The current branch will have an asterisk*next to it.git branch [branch-name]
Creates a new branch based on your current branch.git checkout [branch-name]
Switches to the specified branch and updates your working directory.git merge [branch-name]
Merges the specified branch’s history into the current branch.
4. Setup & Init
Configuring User Information, Initializing, and Cloning Repositories
git init
Initializes an existing directory as a Git repository.git clone [url]
Retrieves an entire repository from a hosted location via URL.
5. Inspect & Compare
Examining Logs, Diffs, and Object Information
git log
Shows the commit history for the currently active branch.git log branchB..branchA
Shows the commits on branchA that are not on branchB.git log —follow [file]
Shows the commits that changed a file, even across renames.git diff branchB...branchA
Shows the diff of what is in branchA that is not in branchB.git show [SHA]
Shows any object in Git in a human-readable format.
6. Share & Update
Retrieving Updates from Another Repository and Updating Local Repos
git remote add [alias] [url]
Adds a Git URL as an alias.git fetch [alias]
Fetches all branches from that Git remote.git merge [alias]/[branch]
Merges a remote branch into your current branch to bring it up to date.git push [alias] [branch]
Transmits local branch commits to the remote repository branch.git pull
Fetches and merges any commits from the tracking remote branch.
7. Tracking Path Changes
Versioning File Removals and Path Changes
git rm [file]
Deletes the file from the project and stages the removal for commit.git mv [existing-path] [new-path]
Changes an existing file path and stages the move.
-⬤