Git Ref
Publish date: Oct 29, 2021
Last updated: Mar 22, 2024
Last updated: Mar 22, 2024
Some of git commands I often use. A living doc.
Task | Syntax |
---|---|
Init new repo | git init |
Configure local user name | git config --local user.name "<USER_NAME>" |
Configure local user email | git config --local user.email "<USER_EMAIL>" |
List local configuration | git config --local --list |
Create new branch | git checkout -b <BRANCH> |
Create remote branch from local branch | git push --set-upstream origin <BRANCH> |
Checkout existing branch | git checkout <BRANCH> |
Delete local branch | git branch -D <BRANCH> |
Delete all local branches except for current banch | git branch | grep -v '^*' | xargs git branch -D |
Delete remote branch | git push --delete --force origin <BRANCH> |
List local branches | git branch |
List remote branches | git branch -r |
Show status | git status |
Show diff | git diff |
Stage all changes | git add . |
Commit staged changes | git commit -m "<MESSAGE>" |
Push local branch to remote branch | git push |
Merge remote branch into local branch | git pull origin <BRANCH> |
Show commit log | git log |
Show pretty commit log | git log --oneline |
Unstage all changes | git reset |
Resets the index and working tree | git reset --hard |
Undo all modified files | git checkout . |
Delete untracked files/directories and .gitignore files | git clean -fdx |
Interactively rebase last n commits |
git rebase -i HEAD~n |
Cleanup local repo | git gc |
Recognize case-only filename changes | git mv -f <OLD_FILE_PATH> <NEW_FILE_PATH> |
Ignore a file that was already committed | git rm -r --cached . && git add . |
Rebase ‘origin/main | git pull --rebase |