Managing multiple Git Identities

If you want to use a different email address between your company repo and your GitHub repo, this configuration will ask you to set your name/email before the first commit.

Make sure there is are no global default username or email.

1
2
git config --global --unset user.name
git config --global --unset user.email

Prevent commits without setting username or email first.

1
git config --global user.useConfigOnly true

Or you could configure identities based on filesystem path. How to use multiple GPG identities

Best Alias: git undo

1
git config --global alias.undo "reset --soft HEAD^"

git undo dissolves your last commit back into the staging area, without losing anything. Allowing you to start over.

Git Bisect

Git Bisect helps you find the commit that introduced the breaking change (the bad commit). If you have a failing test you can even automate it! I got a lot of value ot ouf it during my career as Software Developer. I recommend you learn it.

git-bisect.png

Git Clients

Most editors have built-in support or a good extension for Git, like sublimemerge. I prefer fork.dev on macOS for its visual diffing. Linux users may want to check out Guitar.

How to ignore a credentials file

It is much safer to instead provide a sample config file.

  1. Add the config.json file with default credentials.
  2. Commit it.
  3. Tell Git to ignore it forever git update-index --skip-worktree config.json

Global Git ignore

You can set your global git ignore in ~/.config/git/ignore source. Or a custom location git config --global core.excludesfile ~/.gitignore

1
2
3
4
.DS_Store
.idea/
Thumbs.db
*~

Exporting master branch without .git

I used to commit articles into the master branch and then export it to a web hoster.

1
git archive master | tar -x -C /somewhere/else

The archive will not contain the .git directory. Excluding additional files

Other things

1
2
3
4
5
6
7
8
9
git log --oneline --graph
git log --oneline --graph --simplify-by-decoration --all
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
git reset --hard master && git clean -f -d # This should reset everything
git checkout --theirs . # If you're already in conflicted state, and you want to just accept all of theirs:
git checkout --ours . # Our ours
git config --global user.useConfigOnly true # require user and mail to be set
git config --global pull.rebase true # isn't this standard?
git config --global push.followTags true # also push all referenced Tags

Links

SSH Tricks

RSA ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa_xxx has been replaced ssh-keygen -a 100 -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519_xxx

Tell SSH exactly what key to use, and not to send anything else. .ssh/config

1
2
3
Host dev.azure.com
	IdentitiesOnly yes
	IdentityFile ~/.ssh/id_ed25519_xxx