Skip to content

Instantly share code, notes, and snippets.

@ammarnajjar
Last active April 24, 2022 15:19
Show Gist options
  • Save ammarnajjar/0543edd10254fe76c3bf5f8f0dd0cb1c to your computer and use it in GitHub Desktop.
Save ammarnajjar/0543edd10254fe76c3bf5f8f0dd0cb1c to your computer and use it in GitHub Desktop.
My git cheat sheet
# set user name
git config --global user.name "Ammar Najjar"
# set user email
git config --local user.email <email>
# set user sign key -S
git config --local user.signingkey <key>
# current branch name
git rev-parse --abbrev-ref HEAD
# get a pattern from a branch name using sed
git rev-parse --abbrev-ref HEAD |sed 's/.*\(PATTERN-HERE\).*/\1/'
# checkout a branch that contains a pattern (as alias)
git config --global alias.gco = "!f() { git branch -a | grep -e $1 -m 1 | sed 's/remotes\\/origin\\///' | xargs git checkout; }; f"
git gco PATTERN-HERE
# ignore git hooks
git commit --no-verify
# set upstream branch to current if it’s not there
git config --global push.default current
# list files changed
git diff --name-only
# create a new branch from a stash
git stash branch <branch-name>
# follow changes for a file throw log (includes renaming)
git log --follow <file>
git log -p --follow <file> # show patch changes
# apply on merge commit, show the diff with merge conflicts, and the resolution (new in 2.36.0)
# https://github.blog/2022-04-18-highlights-from-git-2-36
git show --remerge-diff
# -G finds commits where "word" appears in the diff
git log -p -Gword
# find all commits where the commit message contains a given word
git log --grep=word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment