Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docs:git:starting_a_new_remote_branch [2010/04/02 16:49] – billh | docs:git:starting_a_new_remote_branch [2010/07/28 16:08] (current) – billh | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== starting a new remote branch ====== | ====== 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 | + | Method |
- | < | + | |
- | (locally start the new branch) | + | |
- | git checkout -b new_feature_name | + | |
- | (push the new local branch to the shared repo) | ||
- | git push origin new_feature_name | ||
- | (other people | + | ===== method 1: start a local branch and push it to the remote ===== |
- | git pull | + | * shared repo has one branch: master |
+ | * user1 creates a new local branch called dev< | ||
+ | $ git checkout -b dev | ||
+ | </ | ||
+ | * push the new local branch to the shared repo:< | ||
+ | $ git push origin dev | ||
+ | </ | ||
+ | * 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%%< | ||
+ | git branch --set-upstream dev origin/ | ||
+ | (output should be: Branch dev set up to track remote branch dev from origin.) | ||
+ | </ | ||
+ | * option 2 - delete the local branch and create it again with %%--track%%< | ||
+ | $ git checkout master | ||
+ | $ git branch -D dev | ||
+ | $ git checkout --track -b dev origin/ | ||
+ | </ | ||
+ | * option 3 - manually edit your .git/config by adding lines similar to the following (this is what %%--set-upstream%% does for you)< | ||
+ | [branch " | ||
+ | remote = origin | ||
+ | merge = refs/ | ||
+ | </ | ||
+ | * user2 can pull changes | ||
+ | $ git pull | ||
- | (the new branch | + | From / |
+ | * [new branch] dev -> origin/ | ||
+ | Already up-to-date. | ||
- | (start tracking the remote branch with a new local branch) | + | $ git checkout --track -b dev origin/ |
- | git checkout --track -b new_branch | + | $ git branch -a |
+ | |||
+ | * dev | ||
+ | master | ||
+ | remotes/ | ||
+ | remotes/ | ||
+ | remotes/origin/master | ||
</ | </ | ||
- | ===== method 2 ===== | + | ===== method 2: push a new branch directly to the shared repo ===== |
- | < | + | * shared repo has one branch: master |
- | (locally start the new branch) | + | * user1 pushes a new branch (dev) to the shared repo< |
- | git checkout | + | $ git push origin origin: |
+ | </ | ||
+ | * user1 now has the following branches locally:< | ||
+ | $ git branch | ||
- | (push all local branches | + | * master |
- | git push --all | + | remotes/ |
+ | remotes/ | ||
+ | remotes/ | ||
+ | </ | ||
+ | * user1 now must create a local branch which is set to " | ||
+ | $ git checkout | ||
+ | $ git branch -a | ||
- | (other people | + | * dev |
- | git pull | + | master |
+ | remotes/ | ||
+ | remotes/ | ||
+ | remotes/ | ||
+ | </ | ||
+ | * user2 can pull changes | ||
+ | $ git pull | ||
- | (the new branch | + | From / |
+ | * [new branch] dev -> origin/ | ||
+ | Already up-to-date. | ||
- | (start tracking the remote branch with a new local branch) | + | $ git checkout --track -b dev origin/ |
- | git checkout --tb new_branch | + | $ git branch -a |
+ | |||
+ | * dev | ||
+ | master | ||
+ | remotes/ | ||
+ | remotes/ | ||
+ | remotes/origin/master | ||
</ | </ | ||
+ | |||
+ | ===== 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 | ||
+ | < | ||
+ | $ git push origin origin/ | ||
+ | </ | ||
+ | |||
+ | ==== remove a remote branch ==== | ||
+ | < | ||
+ | git push origin : | ||
+ | </ | ||
+ | |||
+ | ===== External Links ===== | ||
+ | * http:// | ||
+ | |||
+ | |||
+ |