- upstream is where you cloned from (
origin
) - downstream is any project that integrates your work
These things are equivalent and refer to the branch named master
on the remote named origin
:
remotes/origin/master
origin/master
origin
- This is because
remotes/origin/HEAD -> origin/master
says the default branch for remoteorigin
isorigin/master
.
- This is because
origin/master
- This is a remote branch, i.e. a local copy of the branch named
master
on the remote namedorigin
- This is a remote branch, i.e. a local copy of the branch named
origin master
origin
is a remotemaster
is a local branch
- Fetch
master
from remoteorigin
, storing the results in the local copyorigin/master
:
git fetch origin master
- Merge
origin/master
into localmaster
with local commits
git merge origin/master
Now we can push new changes (local commits + remote updates) back to origin
:
git push origin master
-
git remote add origin https://…
creates a new connection to a remote namedorigin
at urlhttps://...
-
git fetch origin feature-branch
fetchesfeature-branch
from remote namedorigin
-
git fetch origin
fetches all branches from remote namedorigin
-
git pull origin
fetches and merges the current branch from the remote namedorigin
git pull ...
is shorthand forgit fetch ...
git merge <retrieved branch heads> <current branch>
git pull --rebase …
is shorthand forgit fetch …
git rebase <retrieved branch heads> <current branch>
-
git push origin feature-branch
pushes thefeature-branch
branch to the remote namedorigin
, creating it if it doesn’t exist remotely
git log sarah --not master --author sarahlim
# with diffs inline:
git log -p sarah --not master --author sarahlim
# On branch sarah
git diff master...
git diff commit1 commit2
changes fromcommit1
tocommit2
git diff --cached
currently staged, but notHEAD
(last commit)git diff HEAD
in working directory, but notHEAD
git diff
in working directory, but not stagedgit diff feature-branch
in working directory, but notfeature-branch
-
git checkout ea12e
moveHEAD
pointer to commitea12e
(“detachedHEAD
”)- Specific commit hash is more specific than a branch
-
git checkout -- file
discards working changes tofile
-
git checkout HEAD file
copiesfile
from current commit to working directory, and stages it -
git checkout file
what does this do? does it stage everything??
git checkout -- <file>...
to discard changes in working directory
git reset HEAD file
andgit reset file
unstages a change but leaves in working directory
PaulBoxley.com – Git caret and tilde
- Caret
^
iterates over parents. Usually a commit only has 1 parent, unless it was from a merge.HEAD^n
gets then
th parent ofHEAD
HEAD^
is short forHEAD^1
- Tilde
~
iterates over first ancestors.HEAD~
is short forHEAD~1
HEAD@{n}
gets then
th entry (based on 0-indexing) in the reflog
Equivalent ways to go back 2 commits from HEAD
:
HEAD^^
HEAD~~
HEAD~2
HEAD@{3}
(note zero-indexing)- NOT!!!
HEAD^2
, which is the second parent of HEAD, if HEAD was a merge, otherwise illegal
git rebase base-branch feature-branch # on any branch
git rebase base-branch # on feature-branch
Equivalently:
- Switch to base
git checkout base-branch
- Create new branch off base
git checkout -b temp-feature-branch
- Cherry pick feature commits onto new branch
git cherry-pick <feature> <commits> <not> <on> <base>
- Switch to the feature branch we’re rebasing
git checkout feature-branch
- Make it point to new branch
git reset --hard temp-feature-branch
- Don’t need the new branch pointer anymore
git branch -d temp-feature-branch
- Don’t use this on public branches!
Squash
slim 1
, slim 2
into a merge commit and push onto john
branch
Rebase john 1
, john 2
, and john 3
on top of master
and move john
pointer there
- Think Like (a) Git
- Coupled with following along at Visualizing Git