This is a draft cheat sheet. It is a work in progress and is not finished yet.
Branching, Merging, and Fetching
git branch [-v] [(--merged | --no-merged)] |
Lists all the alive branches |
git branch <branch> <remote> |
Creates a new branch |
git branch -d <branch> |
Deletes a branch |
git checkout <branch> |
Switches to a branch |
git checkout -b <branch> |
Creates and switches to a new branch |
git merge <branch> |
Merges the checked-out branch with the <branch> one |
git fetch [<remote>|--all] |
Updates the local info about the remote branch data |
git push [-u] <remote> <branch>[:<remote_branch>] |
Pushed the branch to the remote server |
git pull <remote> |
Fetches and pulls a remote branch |
git rebase <remote> |
From last common ancestor, applies remote, then local changes |
|
|
Git Status Checks
git status [-s] |
Checks the status of local repo |
git check --diff |
Checks for trailing whitespaces |
git diff [--cached] |
Shows staged and unstaged changes |
git log [-p] [-n] [--grep [--pretty] [-Sfoo] |
Shows the repo history |
Undoing Things
git commit --amend |
Undoes the last commit |
git reset HEAD <file> |
Unstages the changes to a file or directory |
git checkout -- <file> |
Undoes the changes to a file or directory |
Tagging
git tag [-l] |
Lists all tags |
git tag -a <tag> [-m <msg>] |
Creates a <tag> tag |
git push <origin> [<tag> | --tags] |
Shares the tag |
git checkout -b <branch> <tag> |
Tag checkout |
|
|
Terms
Tracking branch |
Local branch that has a direct relationship to a remote branch |
Refspec |
Patch |
Get latest from Git branch
git fetch origin/<branch>
git rebase origin/<branch>
git merge origin/<branch>
|
Add file to .gitignore
git rm --cached <file>
echo '<file>' .gitignore
git commit -m "Added <file> to .gitignore"
|
Removes file from git, keeping them in the hard drive
Tagging Later
git log --pretty=online
git tag -a <tag> <tag> <commit_hash>
|
Common aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
|
|