git
undo merge that hasn't been pushed
git reset --merge HEAD~1
roll back hard
git reset --hard <commit/tag>
force push of a previous commit
git push -f origin <commit_id>:<branch>
delete remote branch
git push --delete origin <branch>
reset local branch after a forced-update (above)
git fetch
git reset origin/<branch> --hard
renaming branch and updating remote
git branch -m old-name new-name
git push origin --set-upstream new-name
git push origin :old-name
set username for single repo
git config user.username 'name'
set signing key for local repo
git config user.signingkey <id>
signing commits
git commit -S -m 'msg'
compare diff between two commits
git diff <commit>...<commit>
compare file diff between two branches
git diff newbranch main -- file.txt
git diff newbranch..main -- file.txt
using the latter syntax, if either side is HEAD
it may be ommitted (e.g., main..
compares main
to HEAD
)
adding separate hunks from file
git add --patch <filename>
git add -p <filename>
options:
-
y
stage this hunk for the next commit -
n
do not stage this hunk for the next commit -
q
quit; do not stage this hunk or any of the remaining hunks -
a
stage this hunk and all later hunks in the file -
d
do not stage this hunk or any of the later hunks in the file -
g
select a hunk to go to -
/
search for a hunk matching the given regex -
j
leave this hunk undecided, see next undecided hunk -
J
leave this hunk undecided, see next hunk -
k
leave this hunk undecided, see previous undecided hunk -
K
leave this hunk undecided, see previous hunk -
s
split the current hunk into smaller hunks -
e
manually edit the current hunk - You can then edit the hunk manually by replacing
+
/-
by#
-
?
print hunk help
stash
git stash
git stash show
unstash
git stash pop
add remote origin
git remote add origin git@gitserver/path/to/repo
add multiple push repos
git remote set-url --add --push origin git@gitserver/original/repo
git remote set-url --add --push origin https://gitserver/another/repo
archive branch
git archive --format zip --outpu /path/to/output.zip <branch>
using hub
pull requests
hub pr list
hub pr checkout <num>