git push -u origin myNewBranch # Pushes your newly created local branch "myNewBranch"
# to the remote "origin".
# So now a new branch named "myNewBranch" is
# created on the remote machine named "origin"
git pull origin myNewBranch # Pulls new commits from branch "myNewBranch"
# on remote "origin" into remote tracking
# branch on your machine "origin/myNewBranch".
# Here "origin/myNewBranch" is your copy of
# "myNewBranch" on "origin"
git checkout myNewBranch # Switch to myNewBranch
git pull # Updates remote tracking branch "origin/myNewBranch"
# to be in sync with the remote branch "myNewBranch"
# on "origin".
# Pulls these new commits from "origin/myNewBranch"
# to local branch "myNewBranch which you just switched to.
$ git checkout new-feature
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream new-feature <remote>/<branch>
$ git remote show origin
* remote origin
Fetch URL: git@github.com:Flimm/example.git
Push URL: git@github.com:Flimm/example.git
HEAD branch: master
Remote branches:
io-socket-ip new (next fetch will store in remotes/origin)
master tracked
new-branch tracked
Local ref configured for 'git pull':
master merges with remote master
new-branch merges with remote new-branch
Local ref configured for 'git push':
master pushes to master (up to date)
new-branch pushes to new-branch (fast-forwardable)
WHERE ---BRANCH TYPE-------- --REFERENCE TARGETS-------
--------------------------------------------------------------
Remote simple branch -----------> remote head (a commit ID)
--------------------------------------------------------------
Local simple branch -----------> local head (a commit ID)
Local local tracking-branch --> local head (a commit ID1)
--> Remote-name/branch-name
Local remote tracking-branch --> local head (a commit ID2)
--> Remote-name/branch-name
--------------------------------------------------------------
简短的词汇表
术语远程的和分支似乎过载。
跟踪分支尤其令人困惑,因为它和跟踪分支不是一回事。
'a snapshot' - A recording of the state of one or more files
and their contents at a given moment in time.
'a commit' - A container holding one snapshot, the date and
time it was recorded, who recorded it, and a
comment to say what it's all about.
'a repository' - A repository of commits, organized so we can
look thru them, going backwards in time.
Much like photos added in sequence to a photo
album book, to record our own history, each commit
contains a snapshot of the exact state of our
project at a given moment in time.
It is used to be able to look backwards in time to
how it was at any recorded previous time.
'Remote' - (Upper case) Short for 'a named remote repository'
(of commits, of snapshots)
'remote' - (Lower case) Located on another git repository
'local' - Located on your local git repository
'a head' - A specific young commit, with no children yet of
it's own (i.e. no other commits yet pointing to it),
but which may link backwards in time to one or more
of it's natural parents.
Also called a growing tip.
Initially set to a <start-point>.
'a branch' - A symbolic name (i.e. an identifier) pointing
to one specific head, and possibly, depending on
the branch type, also pointing to a remote branch.
The term 'branch' can also refer to a specific
linked list of multiple commits (plural), starting
from the growing tip (or most recent baby), and
linking offspring to their parent(s) backwards in
time.
'tracks' - As we move forward, tracks are what we leave behind.
'tracked' - To be followed, as in, to come afterwards, or after
the fact, by way of the evidence left behind, of the
a state of being of the thing being tracked, as it
moves forwards in time.
'tracking' - The process of capturing and organizing snapshots of
our project so we can later look backwards in time
to find how it previously was.
'tracking-branch' - This term is somewhat redundant, and confusing,
but does have a specific, important meaning.
I have deliberately added the hyphen, because this
term does NOT mean simply 'tracking branch'. (Grab
your aspirin, and a cold pack for your head, lol.)
Because all branches in git are used for, and only
used for, tracking your project, therefore it could
be said that ALL branches are actually
'tracking-branches', but we don't call them that.
Instead we call them, simply 'branches'.
But then what is a 'tracking-branch'?
TL;DR A 'tracking-branch' is a local name that points to
two branches at the same time.
So when you read 'tracking-branch, it might be
helpful to instead think: 'branch-pair'.
(Normal branches only point to one thing, the
head, which is the commit at a growing tip.
And they do not have any symbolic pointers.)
1) The first branch a 'tracking-branch' points to
is the same as for any other branch: a local head,
(i.e. a young commit in our local repository without
any children.) This is where a tracking-branch
keeps a full local copy of a remote branch.
Note that it doesn't necessiarialy hold a full
duplicate copy of the entire second, remote
repository. If you have cloned the remote
repository then you already have most, if not all
of their commits in your own local repository.
2) The second branch a 'tracking-branch' points to
is a branch on a remote repository.
It does this with a <remote-name>/<branch-name>.
The 'remote-name' is used to find the URL to the
remote repository. See `git remote -v`.
Why point to two branches?
This is to be able to operate on two heads at the
same time, like to copy commits from one head to
the other as `git fetch` and `git push` does.
We have two types of 'tracking-branches' (both on
our local repository):
'local tracking-branches',
with a simple branch name, and
'remote tracking-branches',
with a path-style branch name.
See `git branch -avv`. For example:
So our 'remote tracking-branches' are not remote
branches, on a remote repository, but rather are
local branches, which have a local head of their
own, pointing to a local commit, and also at the
same time symbolically pointing, to a remote
branch.
With `git branch -avv`, notice how two branches can
point to origin/remote:
* the first being the 'local-tracking-branch'
with the name 'master', and with the
'[origin/master]' extra clause, and
* the second being the 'remote-tracking-branch'
with the name 'origin/master'.
NOTE: Though they point to the same remote branch,
the local commit head is not always the same!
Thus they are actually two different branches.
The 'local-tracking-branch' is our working branch,
and the 'remote-tracking-branch' is a copy of the
remote's branch that we cloned from or fetched to
update.
调查
遥控器
git remote # List names of known Remotes
git remote -v # List names of known Remotes and
# show the 2 URL's pointing to them
#
# See '[remote "<names>"]' in
# $ cat .git/config
远程分支(位于远程存储库上)
git remote show <remote-name> # Download and view
# a specific Remote's info.
# for example, let's download the information for
# two remotes named origin and upstream:
git branch -avv # Show ALL 'local branches', verbosely; (3 types):
git branch -rv # -- type 1 -------------------------------------
# Show ONLY 'local branches' that point to
# 'remote branches' (-r = remote; -v = verbose)
#
# This lists your 'Remote tracking branches'!
# From: $ tree .git/refs/remotes/*
#
# They allow us to move snapshots between
# repositories, and to keep a copy of
# Remote's branches locally.
git branch -vv # -- types 2 and 3 ------------------------------
# Show ONLY 'local branches', that point to local
# things, but his includes two different types of
# branches mixed together, for example:
* master de430b6 [origin/master] <comment describing this branch>
updates 3c40299 [origin/updates] <comment describing this branch>
foo de430b6 <comment describing this branch>