Git
Config#
You can set some useful configs in your .config/git/config:
[user] email = john.smith@omg.lol name = John Smith[gpg] format = ssh[commit] gpgsign = true[push] autosetupremote = true useForceIfIncludes = true[pull] rebase = trueIt can also be useful to add the following to your global .gitignore (located by default in ~/.config/git/ignore):
.idea.DS_Storenode_modulesSee more cool git options explained here.
Usage#
Update branch#
Update my branch with the latest changes from main.
git fetchgit merge origin/maingit switch#
git switch is the new limited version of git checkout see this StackOverflow thread for more details.
Create a branch.#
git switch -c $BRANCH_NAMEGo back to previous branch.#
git switch -Force push#
Force push only if your changes are the latest changes on the remote. This prevents you from overwriting someone else’s changes. See more details.
git push --force-with-leasePull#
git pull --rebaseAbort if there are conflicts
git rebase --abortPull with merge to resolve conflict
git pull --no-rebase # or use `git pull` with `git config --global pull.rebase false`Ignore specific commits in git blame#
Sometimes, you will commit large formatting changes which makes git blame fairly useless because almost every line will have the formatting change as its most recent commit.
With git config blame.ignoreRevsFile .git-blame-ignore-revs, you can create a .git-blame-ignore-revs file containing commit SHAs that should be ignored by git blame in VSCode and GitHub. GitHub supports .git-blame-ignore-revs files natively without configuration.
[blame] ignoreRevsFile = .git-blame-ignore-revsExample of a .git-blame-ignore-revs file.
# Enforced single quotes over double quotes7e9386274b3b969b70ae4beda1b3321812c1c512Store large files in git#
git works best with text files and while you can version other file types with it, it is usually not advised. Instead, you can use Git LFS to manage these larger files.
GitHub SSH Key#
Tutorial for creating a new SSH key and adding it to GitHub
Securing GitHub SSH Key#
It is a best practice to secure your SSH keys using a passphrase but it can be annoying to enter your passphrase every time you want to push / pull from GitHub.
You can reduce the number of times you have to enter your passphrase by adding your ssh key to the ssh-agent.