March 13, 2025 (updated November 13, 2026)
🌲 = Evergreen note, updated regularly.
A collection of Git commands I use often but tend to forget.
Create a new branch:
git branch <branch-name>
Switch to a branch:
git switch <branch-name> or git checkout <branch-name>
Create a new branch and switch to it in one go:
git checkout -b <branch-name>
Merge a branch:
Switch to a branch that you want to merge into, then:
git merge <name-of-branch-to-merge>
Delete a branch locally:
git branch -d <name-of-branch-to-delete>
Delete a branch in remote repository:
git push origin --delete <name-of-branch-to-delete>
List remote repositories:
git remote -v
Change remote repository URL:
git remote set-url origin <new-url>
Add a tag to a commit:
git tag <tag-name>
Push tags to remote repository (they are not pushed when you push your code):
git push origin --tags
List current configurations:
git config -l
Omit files from being checked for changes:
git update-index --assume-unchanged <path-to-file>
Be careful with this command. If you use it on files that you’ve made changes to, these files and changes will effectively become untracked and some operations might silently overwrite them or otherwise lead to the loss of changes. In other words, it is very easy to forget that you’ve set some files to be assumed unchanged and there are no warnings when these files are being affected by some processes. Your best bet is to write the files you’ve set to be assumed unchanged on a Post-It note and stick it on your computer monitor.
Undo the above:
git update-index --no-assume-unchanged <path-to-file>
List files marked with --assume-unchanged:
git ls-files -v