2017年7月13日 星期四

[ Git 常見問題 ] Git fetch/create remote branch

Source From Here 
Create a remote Git branch 
First, you create your branch locally: 
# git checkout -b  // Create a new branch and check it out

The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can just do: 
# git push

Where is typically origin, the name which git gives to the remote you cloned from. Your colleagues would then just pull that branch, and it's automatically created locally. 

Note however that formally, the format is: 
# git push :

But when you omit one, it assumes both branch names are the same. Having said this, as a word of cautiondo not make the critical mistake of specifying only : (with the colon), or the remote branch will be deleted! 

So that a subsequent git pull will know what to do, you might instead want to use: 
# git push --set-upstream

As described below, the --set-upstream option sets up an upstream branch: 
For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands


Source From Here 
Fetch remote branch 
You need to create a local branch that tracks a remote branch. The following command will create a local branch named daves_branch, tracking the remote branch origin/daves_branch. When you push your changes the remote branch will be updated. For most versions of git: 
# git checkout --track origin/daves_branch

--track is shorthand for git checkout -b [branch] [remotename]/[branch] where [remotename] is origin in this case and [branch] is twice the same, daves_branch in this case. 

For git 1.5.6.5 you needed this: 
# git checkout --track -b daves_branch origin/daves_branch


For git 1.7.2.3 and higher this is enough (might have started earlier but this is the earliest confirmation I could find quickly): 
# git checkout daves_branch

Note that with recent git versions, this will command not create a local branch and will put you in a 'detached HEAD' state. If you want a local branch, use the --track option. Full details here: http://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches 

Supplement 
GitPro - Git Branching

沒有留言:

張貼留言

[Linux 常見問題] What's the best way to send a signal to all members of a process group?

Source From  Here   Question   I want to  kill a whole process tree.  What is the best way to do this using any common scripting languages? ...