The list of helpful git commands was growing too large, so compiling into one page.
git fetch origin <REMOTE_BRANCH>:<LOCAL_BRANCH>
Pull all changes:
git pull --recurse-submodules
Reset changes to submodules (including fast-forwards):
git submodule deinit -f . git submodule update --init
# From old page
git config user.email [EMAIL]
or user.name [NAME]
git config --global core.editor vim
git commit --amend --reset-author --no-edit
git commit --amend --author "[NAME] <[EMAIL]>" --no-edit
git reset --hard && git clean -dfx
git diff > [FILE]
git apply --whitespace=fix --reject [FILE]
wiggle --replace [FILE] [FILE.rej]
git add -p .
git rebase --committer-date-is-author-date --rebase-merges -i [COMMIT]~
git add
and git commit --amend
git rebase --continue
git commit --fixup=[COMMIT]
git stash
git rebase -i --autosquash [COMMIT]^
git stash pop
git config --global rebase.autoSquash true
git switch -c [BRANCH]
git cherry-pick -x [COMMIT]
git push --set-upstream origin [BRANCH]
By default, GPG keys are used for signing commits (manually using -S
flag).
As of Git 2.34 (Nov 2021), SSH keys can also be used to sign commits.
git config --global commit.gpgsign true
git config --global gpg.format ssh
git config --global user.signingkey [PUB_KEY]
git log --show-signature
("No signature" for SSH)git config --global alias.adog "log --all --decorate --oneline --graph"
git branch -a --sort=-committerdate
git reflog expire --expire-unreachable=now --all && git gc --prune=now
apt install git-svn
gitk
git remote add all GITREPO1
(sets fetch)git remote set-url --add --push all GITREPO1
(overrides push)git remote set-url --add --push all GITREPO2
(appends push)git push -u all main
(set upstream to all)[core] autocrlf = false [alias] adog = log --all --decorate --oneline --graph
[user] name = pyuxiang signingkey = ... [commit] gpgsign = true [gpg] format = ssh [alias] # Personal adog = log --all --decorate --oneline --graph addw = -c interactive.diffFilter='git diff --color=always --word-diff' add -p diffw = diff --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+' diff-staged = diff --cached # Common operations remove = reset --mixed HEAD uncommit = reset --soft HEAD~ recommit = commit --amend # Get lists of stuff branches = branch -a tags = tag -l --sort=v:refname stashes = stash list remotes = remote -v