docs:git:working_copies_of_multiple_branches

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:git:working_copies_of_multiple_branches [2009/11/08 00:23] billhdocs:git:working_copies_of_multiple_branches [2009/11/08 01:07] (current) billh
Line 1: Line 1:
 ====== working copies of multiple branches ====== ====== working copies of multiple branches ======
-Sometimes during development we need to have working copies of more than one branch at the same time.  With svn this was simple, because working copies of each branch (and/or trunk) would exist at the same time after a checkout. +Sometimes during development we need to have working copies of more than one branch at the same time.  With svn this was simple, because working copies of each branch (and/or trunk) would exist at the same time after a checkout.  A single working copy using git would only reflect the active branch.
- +
-A single working copy using git would only reflect the active branch.  My preference for doing this with git was to have a "master" working copy with my repo that would hold all changes, and another cloned copy that would act as the alternate branch.+
  
 (assume master working copy/repo is at /foo/base/.git) (assume master working copy/repo is at /foo/base/.git)
 +
 +===== simple solution =====
 +I want to work on an upstream branch other than "master".
 +<code>
 +cd /foo/base
 +git branch alt
 +  (make sure you have a branch called 'alt' in the main repo before cloning)
 +cd ..
 +git clone /foo/base /foo/alt
 +cd /foo/alt
 +git branch -a
 +  (see that alt is not there because only master is tracked; unless another branch was active!)
 +git checkout --track -b alt origin/alt
 +  (this creates a local branch 'alt' based on the upstream branch and switches your working
 +  copy to that branch; git push, git fetch, git pull are all configured automatically)
 +git pull
 +git push origin alt
 +  (you can also just run 'git push' unless you don't want to update other branches)
 +</code>
 +
 +Your .git/config file will show the alt branch configured like this:<code>
 +[branch "alt"]
 +    remote = origin
 +    merge = refs/heads/alt
 +</code>
 +
 +===== manual solution =====
 +:!:Please use the "simple solution" above instead.  This solution is kept to see how it can manually be done.
 +
 +My preference for doing this with git was to have a "master" working copy with my repo that would hold all changes, and another cloned copy that would act as the alternate branch.
 +
 <code> <code>
 mkdir /foo/alt mkdir /foo/alt
Line 47: Line 76:
 </code> </code>
  
-===== adding git pull capability =====+===== manually adding git pull capability =====
 git pull actually does a git fetch then a git merge operation for you.  If you want to also be pulling (merging) any changes that occur on this alt branch on the main repo (/foo/base), you can run this:<code> git pull actually does a git fetch then a git merge operation for you.  If you want to also be pulling (merging) any changes that occur on this alt branch on the main repo (/foo/base), you can run this:<code>
 git config branch.alt.remote origin git config branch.alt.remote origin
Line 60: Line 89:
  
 You should now be able to 'git pull' and merge any changes from the main repo. You should now be able to 'git pull' and merge any changes from the main repo.
 +
 +===== External Links =====
 +* [[http://www.sourcemage.org/Git_Guide|Git Guide]] (see section titled **I want to work on an upstream branch other than "master"**)
 +
  • docs/git/working_copies_of_multiple_branches.1257665015.txt.gz
  • Last modified: 2009/11/08 00:23
  • by billh