git log main.. # commits in HEAD only
git log A...B # commits in B only and in A only
git diff foo..bar # changes introduced by both
git diff foo...bar # changes in bar only
- a branch is a pointer to a commit
HEAD
points to the current branch #git checkout br1
movesHEAD->br1
- The
HEAD
branch moves forward when a commit is made
git ls-remote origin -> refs/heads/main # *heads* refers to 'branches'
you do that in order to use git pull/push without arguments (implied origin + remote)
note: origin/main
is called a remote-tracking branch. it's a local reference/pointer that can't be moved
git checkout -b <branch> <remote>/<branch>
git checkout --track origin/serverfix
git checkout serverfix
git branch -u origin/serverfix
git push -u origin my-branch # set origin/my-branch (@{u[pstream]}) as upstream for my-branch
└─ or HEAD if on the branch
git fetch --prune
git remote prune origin
git rebase main experiment
or
git checkout experiment
git rebase main
git checkout main
git merge experiment
Apply any commit to the current branch
git cherry-pick 3c9b10a # this commit comes from another branch
we now have a duplicate commit (it exists in 2 branches) => only do if you don't want the whole other branch!
Everything tracked is in your staging area - the index
git rm --cached # untrack: remove from index
git rm # rm: remove from index and working copy
git commit --amend
, same as:
git reset --soft HEAD^
- modify staging area
git commit
uncommit file example:
git reset @~ file
git commit --amend -m'...'
Our need is to change the commits...
- move the
HEAD->branch
pair to another commit. - update index: stop here by default (change with --soft/hard)
- optionally update the working dir
HEAD (--soft) ⇒ Index ⇒ Working dir (--hard)
example 1: git reset HEAD~
- move
HEAD->branch
to previous commit => undo last commit - update index with the snapshot
HEAD->branch
points to => unstage everything
example 2: git reset main
- move
HEAD->branch
to wheremain
points - ...
- Here, commit history isn't the issue, plus changing commit would affect many files => so skip this step
- unstage file or more accurately, copy file from HEAD to index
git reset file
: unstage file (opposite of git add file)git reset
: unstage all filesgit reset --hard
: unstage everything + reset working dirgit checkout main~2 file
: update the index + working dir frommain~2
commit (default isHEAD
)git reset --hard main~2 file
would do the same thing.
- it's a local history of all (no history rewriting as with
git log
) commits - ring buffer with a limited amount of data (a few months)
git checkout [commit] # same as:
git reset --hard [commit] # but working-dir safe + only moves HEAD
git checkout [commit] file # same as:
git reset --hard [commit] file # but not implemented in git-reset
git checkout -b topic main
same as:
git branch topic main
git checkout topic
- fetch =
+src(_remote_):dst(_local_)
- push =
+src(_local_):dst(_remote_)
+
: update the reference even if it isn’t a fast-forward
remote branches refs/heads/\*
go under refs/remotes/origin/*
locally: fetch = +refs/heads/\*:refs/remotes/origin/*
these are equivalent:
git push origin serverfix
git push origin serverfix:serverfix
git push origin refs/heads/serverfix:refs/heads/serverfix
git push origin --delete topic
git push origin :topic
<- push emptysrc
to remote
fd --strip-cwd-prefix -FIH -td .git | parallel --tag --tagstring '{//}' 'git -C {//} branch' | grep -v 'main$'
fd --strip-cwd-prefix -FIH -td .git | parallel --tag --tagstring '{//}' 'git -c color.status=always -C {//} status -sb'
git config --global credential.https://github.aaakk.us.kg.username kurkale6ka
git config --global credential.helper store
then git push
will ask for the token/password
parent commit of HEAD
: HEAD^
or HEAD~
or @~