Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
docs:git:working_copies_of_multiple_branches [2009/11/07 22:50] – created billh | docs: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 | + | |
(assume master working copy/repo is at / | (assume master working copy/repo is at / | ||
+ | |||
+ | ===== simple solution ===== | ||
+ | I want to work on an upstream branch other than " | ||
+ | < | ||
+ | cd /foo/base | ||
+ | git branch alt | ||
+ | (make sure you have a branch called ' | ||
+ | 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 ' | ||
+ | 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) | ||
+ | </ | ||
+ | |||
+ | Your .git/config file will show the alt branch configured like this:< | ||
+ | [branch " | ||
+ | remote = origin | ||
+ | merge = refs/ | ||
+ | </ | ||
+ | |||
+ | ===== manual solution ===== | ||
+ | :!:Please use the " | ||
+ | |||
+ | My preference for doing this with git was to have a " | ||
+ | |||
< | < | ||
mkdir /foo/alt | mkdir /foo/alt | ||
Line 11: | Line 40: | ||
git branch alt | git branch alt | ||
git checkout alt | git checkout alt | ||
+ | </ | ||
+ | |||
+ | This line actually modifies your .git/config file:< | ||
git config remote.origin.push alt:alt | git config remote.origin.push alt:alt | ||
+ | </ | ||
+ | |||
+ | The way it modifies the file looks like this:< | ||
+ | # BEFORE | ||
+ | [remote " | ||
+ | fetch = +refs/ | ||
+ | url = / | ||
+ | |||
+ | # AFTER | ||
+ | [remote " | ||
+ | fetch = +refs/ | ||
+ | url = / | ||
+ | push = alt:alt | ||
+ | </ | ||
+ | |||
+ | < | ||
# work work work | # work work work | ||
git push | git push | ||
Line 27: | Line 75: | ||
* [new branch] | * [new branch] | ||
</ | </ | ||
+ | |||
+ | ===== 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 (/ | ||
+ | git config branch.alt.remote origin | ||
+ | git config branch.alt.merge refs/ | ||
+ | </ | ||
+ | |||
+ | The above commands will modify your / | ||
+ | [branch " | ||
+ | | ||
+ | merge = refs/ | ||
+ | </ | ||
+ | |||
+ | You should now be able to 'git pull' and merge any changes from the main repo. | ||
+ | |||
+ | ===== External Links ===== | ||
+ | * [[http:// | ||
+ |