Note: Git commands

This is a simple reference listing Git commands I use often but tend to forget.

Branches


Create a new branch:
git branch <branch-name>


Switch to a branch:
git checkout <branch-name>
or
git switch <branch-name>


Create a new branch and switch to it in one go:
git checkout -b <branch-name>

Remote repositories


List remote repositories:
git remote -v


Change remote repository URL:
git remote set-url origin <new-url>

Configuration


List current configurations:
git config -l

Other


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