| | Command |
| Getting started |
| Set name and email for commits | git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com" |
| General |
| Only clone with latest revision | git clone --depth 1 <url> |
| Get new metadata but don't pull | git fetch |
| Check what would be added without adding | git add --dry-run . or
git status -u |
| Diffs |
| Show changes (no pager) | git --no-pager diff |
| Show changed files | git diff --name-only |
| Undo |
| Undo and delete all local changes | git reset --hard |
| Cleanup untracked files | git clean -fd |
| Revert a commit | git revert <SHA> |
| Revert uncommitted changes | git checkout -- <file> |
| Branching |
| Create new branch | git checkout -b <branchname> |
| Change to branch | git checkout <branchname> |
| Push to new branch | git push -u origin <branchname> |
| Merge branch to master | git checkout master
git merge <branchname>
git push |
| Check which branches exist | git show-branch |
| Delete local branch | git branch -d <branchname> |
| Delete remote branch | git push origin --delete <branchname> |
| Mirrors |
| Download a mirror clone | git clone --mirror <url> |
| Change push URL of local repo | git remote set-url --push origin <mirrorurl> |
| Fetch updates from original | git fetch -p origin |
| Push to mirror | git push --mirror |
| Various |
| Specify repository location | git -C <path to repository> <command> |
| Get remote URL of repository | git remote get-url |
| Set new remote URL for repository | git remote set-url origin <url> |