This is an old revision of the document!
Overview
Discussion and demonstration of remote tracking branches and adding remotes.
ADD
$ git ls-remote [<remote>] $ git remote show <remote> $ git remote prune
$ git fetch --all; git branch -vv $ gut push origin thisbranch:thatbranch $ git push origin --delete <branchname>
$ git checkout --track origin/serverfix
Example with the Linux kernel
To start, consider the status of the local tracking branch master:
$ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working tree clean $
If we want to fetch new content but not merge it with our local tracking branch, we can just fetch the new content to the remote tracking branch origin/master:
$ git fetch remote: Counting objects: 85, done. remote: Total 85 (delta 70), reused 70 (delta 70), pack-reused 15 Unpacking objects: 100% (85/85), done. From https://github.com/torvalds/linux 7928b2cbe55b..61f14c015f5b master -> origin/master $
Note what git status tells us now:
$ git status On branch master Your branch is behind 'origin/master' by 13 commits, and can be fast-forwarded. (use "git pull" to update your local branch) nothing to commit, working tree clean $
You can check out a remote tracking branch, but you shouldn't try to make any changes to it -- that's not what it's for:
$ git checkout origin/master Note: checking out 'origin/master'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at 61f14c015f5b... Merge tag 'mips_4.16_2' of git://git.kernel.org/pub/scm/linux/kernel/git/jhogan/mips $
Adding the "linux-next" remote
Based on the web page here, first verify that there is only one remote:
$ git remote origin $ git remote -v origin https://github.com/torvalds/linux.git (fetch) origin https://github.com/torvalds/linux.git (push) $
Add the remote with whatever meaningful name works for you:
$ git remote add ln \ > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git $
Verify you have a second remote:
$ git remote -v ln https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git (fetch) ln https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git (push) origin https://github.com/torvalds/linux.git (fetch) origin https://github.com/torvalds/linux.git (push) $
Now fetch the new content from the new remote:
$ git fetch [--tags] ln remote: Counting objects: 109900, done. remote: Compressing objects: 100% (19971/19971), done. remote: Total 109900 (delta 95864), reused 103738 (delta 89778) Receiving objects: 100% (109900/109900), 17.48 MiB | 1.14 MiB/s, done. Resolving deltas: 100% (95864/95864), completed with 4062 local objects. From https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next * [new branch] akpm -> ln/akpm * [new branch] akpm-base -> ln/akpm-base * [new branch] master -> ln/master * [new branch] stable -> ln/stable * [new tag] next-20171115 -> next-20171115 * [new tag] next-20171116 -> next-20171116 * [new tag] next-20171117 -> next-20171117 * [new tag] next-20171120 -> next-20171120 * [new tag] next-20171121 -> next-20171121 ... big snip ... $
List all remote branches in the object store:
$ git branch -r ln/akpm ln/akpm-base ln/master ln/stable origin/HEAD -> origin/master origin/master $
Start tracking:
$ git checkout -b lnmaster --track ln/master