Skip to content

Latest commit

Β 

History

History
105 lines (69 loc) Β· 3.72 KB

File metadata and controls

105 lines (69 loc) Β· 3.72 KB

Git Tips

This file covers different, advanced use cases of git with practical shell examples.

Finding source of conflicts

πŸ’‘ Did you ever wondered where a PR conflict comes from?

With a lot of stuff merged on the default branch, e.g. develop, between opening the PR and finally merging it quite some time can pass.

On the command line you can run the following for the conflicting file, which will give you

  • author
  • commit message
  • commit date and
  • some more meta infos about the conflicting file since the specified date

Regarding the date, it would be clever to enter the PR opening date 🀷

git log --since="2026-02-03" --stat -- <path/to/file>

Now you can simply check the content of the logged commits on GitHub which makes it WAY easier to solve the conflict. If you like the console VERY much, you can also view the changes directly there by replacing --stat by -p πŸ‘

Git Superpowers with forgit

πŸ’‘ Did you ever wish git commands were more interactive and faster to use?

forgit gives git superpowers by creating tons of aliases for git on top of the fuzzy finder FZF. It makes browsing logs, staging files, and viewing diffs a breeze β€” all interactively in the terminal.

glo     # interactive git log
ga      # interactive git add (stage files)
gd      # interactive git diff
gco     # interactive git checkout
gcf     # interactive git checkout file
gcb     # interactive git checkout branch
gbd     # interactive git branch delete
grh     # interactive git reset HEAD
gi      # interactive .gitignore generator
gfu     # interactive git fixup
gclean  # interactive git clean
gss     # interactive git stash show
gcp     # interactive git cherry-pick

Smart Fixup Commits with git absorb

πŸ’‘ Do you struggle to figure out which commit a staged change belongs to when working on a PR?

When your staged changes need to be fixed up across multiple commits, git absorb does the heavy lifting for you. It checks for each hunk of your staged changes which existing commit is the right candidate for a fixup and automatically creates the fixup commit.

git absorb

Further info: Super-charging git rebase with git absorb

Never Manually Stash Again with autoStash

πŸ’‘ Do you still do stash β†’ rebase β†’ pop when rebasing or pulling with local changes?

Enable autoStash in your global ~/.gitconfig and never think about it again. When performing a rebase or a pull it automatically stashes your local changes and reapplies the stash afterwards.

This is super convenient not just for rebasing but also when pulling your co-workers' changes while you have uncommitted work in progress.

[rebase]
    autoStash = true

Further info: Git tip: autostash with git pull --rebase

Branch Descriptions

πŸ’‘ Did you know that you can add a description text to a branch?

With many branches and experiments laying around that comes in very helpful. Sadly the description is not synced with remote, but at least it is possible locally. Set it with:

git branch --edit-description

And retrieve it using:

git config branch.$(git branch --show-current).description

Supercharged git status

πŸ’‘ Do you want to take your terminal's git status display to the next level?

Create an alias in your ~/.zshrc like so:

alias gst="git status -sb"

The difference is plain great simplicity 🀩

git status -sb git status
git status -sb git status