Cheat Sheet Git
Basics
| Command |
Description |
| git --help |
List help commands |
| git --version |
Get installed Git version |
| git update-git-for-windows |
Update the installed version of Git |
Configuration
| Command |
Description |
| git config -l |
Lists information about your git configuration |
| git config --global user.name "[firstname lastname]" |
Set the name for commits and tags |
| git config --global user.email "[email address]" |
Set the e-mail address for commits and tags |
| git config --global color.ui auto |
Set automatic command line coloring for Git |
Setup a Project and Clone to Local
| Command |
Description |
| git init |
Initialize a new local repository in the current directory |
| git init "[project name]" |
Initialize a new local repository in a new directory |
| git clone "[project url]" |
Download a remote repository with all history |
Add Changes
| Command |
Description |
| git add [file] |
Add a file to staging |
| git add . |
Add all files to staging |
| git add -p |
Prompt to stage changes interactively |
| git add fil* |
Add files starting with fil to staging |
Show Differences
| Command |
Description |
| git diff |
Display unstaged changes |
| git diff --staged |
Display staged changes |
Commit Changes
| Command |
Description |
| git status |
List staged, unstaged, and untracked files |
| git commit |
Commit files, opens editor for comment |
| git commit -m "[comment]" |
Commit all staged files with a comment |
| git commit -a -m "[comment]" |
Add and commit in one go with a comment |
Authentication
| Command |
Description |
| ssh -vT git@github.com |
Test your SSH keys |
Work with Remote Repositories
| Command |
Description |
| git add remote [repository URL] |
Add a remote repository |
| git remote -v |
List all remote repositories |
| git remote show origin |
Display details about the remote repository |
| git push |
Upload staged changes to the remote |
| git pull |
Download changes from the remote |
| git remote set-url origin git@github.com:yourusername/yourrepository.git |
Switch to SSH URL |
Remove Changes
| Command |
Description |
| git checkout [filename] |
Revert an unstaged file |
| git reset HEAD [filename] |
Revert a staged file |
| git reset HEAD -p |
Prompt to revert staged files |
Revert a Commit
| Command |
Description |
| git revert HEAD |
Create a new commit that undoes the last |
| git revert [commit id] |
Revert to an old commit by ID |
Delete Files
| Command |
Description |
| git rm [filename] |
Delete a file from the working tree |
Change Existing File
| Command |
Description |
| git mv [old file] [new file] |
Rename a file |
Branches
| Command |
Description |
| git branch |
List all branches |
| git branch [new_branch] |
Create a new branch |
| git checkout [different_branch] |
Switch to a branch |
| git checkout -b [new_branch] |
Create and switch to a new branch |
| git branch -d [branch] |
Delete a branch |
| git merge [branch] |
Merge another branch into current |
Logs
| Command |
Description |
| git log |
Display all logs |
| git log [-n] |
Display logs limited by [-n] |
| git log -p |
Display logs and file changes |
| git log --stat |
Display logs and statistics |
References
50 Commands you should know