Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== starting a new remote branch ====== In the examples below, there is a shared repo (shared), a user1 (doing the branch changes), and a user2 (needs to pull the branch changes). Method 1 may be better for you if the branch already exists locally, and you need that history pushed to the shared repo. ===== method 1: start a local branch and push it to the remote ===== * shared repo has one branch: master * user1 creates a new local branch called dev<code> $ git checkout -b dev </code> * push the new local branch to the shared repo:<code> $ git push origin dev </code> * but wait - even though user1 created the branch and pushed it to the remote, the local branch is not yet tracking the shared branch * option 1 - use %%--set-upstream%%<code> git branch --set-upstream dev origin/dev (output should be: Branch dev set up to track remote branch dev from origin.) </code> * option 2 - delete the local branch and create it again with %%--track%%<code> $ git checkout master $ git branch -D dev $ git checkout --track -b dev origin/dev </code> * option 3 - manually edit your .git/config by adding lines similar to the following (this is what %%--set-upstream%% does for you)<code> [branch "dev"] remote = origin merge = refs/heads/dev </code> * user2 can pull changes to see the new branch, then use the same command as user1 to create a local branch and track the remote branch:<code> $ git pull From /path/to/shared/repo * [new branch] dev -> origin/dev Already up-to-date. $ git checkout --track -b dev origin/dev $ git branch -a * dev master remotes/origin/HEAD -> origin/master remotes/origin/dev remotes/origin/master </code> ===== method 2: push a new branch directly to the shared repo ===== * shared repo has one branch: master * user1 pushes a new branch (dev) to the shared repo<code> $ git push origin origin:refs/heads/dev </code> * user1 now has the following branches locally:<code> $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/dev remotes/origin/master </code> * user1 now must create a local branch which is set to "track" the new remote branch:<code> $ git checkout --track -b dev origin/dev $ git branch -a * dev master remotes/origin/HEAD -> origin/master remotes/origin/dev remotes/origin/master </code> * user2 can pull changes to see the new branch, then use the same command as user1 to create a local branch and track the remote branch:<code> $ git pull From /path/to/shared/repo * [new branch] dev -> origin/dev Already up-to-date. $ git checkout --track -b dev origin/dev $ git branch -a * dev master remotes/origin/HEAD -> origin/master remotes/origin/dev remotes/origin/master </code> ===== Advanced Topics ===== ==== creating a new remote branch from a branch other than master ==== we want to create a new remote branch called foo2 from an existing remote branch called foo <code> $ git push origin origin/foo:refs/heads/foo2 </code> ==== remove a remote branch ==== <code> git push origin :old_branch_to_be_deleted </code> ===== External Links ===== * http://cheat.errtheblog.com/s/git docs/git/starting_a_new_remote_branch.txt Last modified: 2010/07/28 16:08by billh