Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
docs:git:starting_a_new_remote_branch [2010/04/04 11:07] billhdocs:git:starting_a_new_remote_branch [2010/07/28 16:08] (current) billh
Line 2: Line 2:
 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). 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 may be better for you if the branch already exists locally, and you need that history pushed to the shared repo.+Method may be better for you if the branch already exists locally, and you need that history pushed to the shared repo.
  
-===== method 1: push new branch directly to the shared repo =====+ 
 +===== method 1: start local branch and push it to the remote =====
   * shared repo has one branch: master   * shared repo has one branch: master
-  * user1 pushes a new branch (dev) to the shared repo<code> +  * user1 creates a new local branch called dev<code> 
-$ git push origin origin:refs/heads/dev+$ git checkout -b dev
 </code> </code>
-  * user1 now has the following branches locally:<code> +  * push the new local branch to the shared repo:<code> 
-$ git branch -a +$ git push origin dev
- +
-* master +
-  remotes/origin/HEAD -> origin/master +
-  remotes/origin/dev +
-  remotes/origin/master+
 </code> </code>
-  * user1 now must create a local branch which is set to "track" the new remote branch:<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 $ git checkout --track -b dev origin/dev
-git branch -a +</code> 
- +    * option 3 - manually edit your .git/config by adding lines similar to the following (this is what %%--set-upstream%% does for you)<code> 
-dev +[branch "dev"] 
-  master + remote = origin 
-  remotes/origin/HEAD -> origin/master + merge = refs/heads/dev
-  remotes/origin/dev +
-  remotes/origin/master+
 </code> </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>   * 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>
Line 44: Line 45:
 </code> </code>
  
-===== method 2: start local branch and push it to the remote =====+===== method 2: push new branch directly to the shared repo =====
   * shared repo has one branch: master   * shared repo has one branch: master
-  * user1 creates a new local branch called dev<code> +  * user1 pushes a new branch (dev) to the shared repo<code> 
-$ git checkout -b dev+$ git push origin origin:refs/heads/dev
 </code> </code>
-  * push the new local branch to the shared repo:<code> +  * user1 now has the following branches locally:<code> 
-$ git push origin dev+$ git branch -a 
 + 
 +* master 
 +  remotes/origin/HEAD -> origin/master 
 +  remotes/origin/dev 
 +  remotes/origin/master
 </code> </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 +  * user1 now must create a local branch which is set to "track" the new remote branch:<code>
-    * option 1 - 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 $ git checkout --track -b dev origin/dev
-</code> +git branch -a 
-    * option 2 - manually edit your .git/config by adding lines similar to the following<code> + 
-[branch "dev"] +dev 
- remote = origin +  master 
- merge = refs/heads/dev+  remotes/origin/HEAD -> origin/master 
 +  remotes/origin/dev 
 +  remotes/origin/master
 </code> </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>   * 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>
  • docs/git/starting_a_new_remote_branch.1270400852.txt.gz
  • Last modified: 2010/04/04 11:07
  • by billh