Over the years, I've tried many workflows, shortcuts, and team conventions while working with git. No two teams worked the same way, but I found a handful of habits that consistently made my life easier. In this post, I'll share the habits and tools that are worth doing. These aren't strict rules or universal standards, just practical lessons learned from real-world projects.
Use a client
git was designed to work as a backend system. UX is not git's forte. Using a client makes your work easier and more visual.
My favorite client is lazygit. It allows me to perform many git operations through a simple interface and it runs on the terminal so that's very universal.
Make atomic commits
Atomic commits mean that each commit should represent one logical change. Avoid making a change in one commit and then overwriting that change in another commit on the same branch. This approach makes several things easier:
-
Code reviews become simpler
-
Debugging with
git bisectworks better -
Reverting changes is straightforward
It's up to you if you amend commits manually and rebase or use fixup commits. Fixup commits are better choice before finishing the process, because it lets you see what you overwrite and easily revert changes if needed.
git commit --fixup <commit-sha-you-want-to-fixup>
You can also use a tool like git-absorb creating atomic commits automatically.
Also, if you use lazygit client, you can easily amend commits or create fixups through the interface.
Sign your commits
Signing commits is important for public repositories. git identities are not protected by security measures. Anyone can pretend to be someone else by using their name and email.
You can sign commits in two ways: GPG and SSH.
GPG was the first way to sign commits. However, I no longer recommend it because managing GPG is a complex process. Of course, it's still a valid choice.
SSH signature verification is available since the version 2.34. This works well if you already use SSH to connect to git repositories.
Add your SSH private key to the local repository:
git config --local user.signingkey <path-to-private-key>
Add your public key to the allowed signers file:
echo "$(git config --get user.email) namespaces=\"git\" $(cat ~/.ssh/<git-ssh-key>.pub)" >> ~/.config/git/allowed_signers
git config gpg.ssh.allowedSignersFile "~/.config/git/allowed_signers"
View signature status for commits:
git log --show-signature
Turn off signing for a specific repository if needed:
git config --local commit.gpgsign false
Set up commit hooks
pre-commit is the most popular tool
for managing commit hooks.
You can also create custom hooks by placing them in the .git/hooks folder.
My only advice here is that when setting up hooks, focus on getting the best value for your time. You do not need to automate everything to the full.
Use force-with-lease instead of force
When you need to rewrite shared history, use --force-with-lease instead of
--force. This option prevents you from overwriting other people's commits
that you have not seen yet.