使用git创建local branch并push到远程

Creating Remote Branches

git branch用得也不是很多,但有时候要用的时候往往会忘记,现将创建远程分支的过程列举如下:

一,确认我们所在的分支

elisonwu$ git branch
* master

 二,假如我们要创建的分支v0

elisonwu$ git branch v0

三,将我们新创建的v0分支提交到远程,让项目组的其他成员都可看得到

git push 语法: git push [remote-repository-name] [branch-or-commit-name]:

elisonwu$ git push origin v0
Total 0 (delta 0), reused 0 (delta 0)
To file:///home/gitadmin/project1.git
 * [new branch]      v0 -> v0

Currently the master and v0 branches are identical, but they will diverge (the whole point of branches is to diverge)
as users make different commits to each branch.

四,configure new branch

当你做完这些还不够,对于本地的branch 的配置不完全

elisonwu$ git checkout v0

   Switched to branch 'v0'

   elisonwwu$ git pull

   You asked me to pull without telling me which branch you

   want to merge with, and 'branch.v0.merge' in

   your configuration file does not tell me, either. Please

   specify which branch you want to use on the command line and

   try again (e.g. 'git pull ').

   See git-pull(1) for details.

   If you often merge with the same branch, you may want to

   use something like the following in your configuration file:

     [branch "v0"]

     remote =

     merge = 

     [remote ""]

     url =

     fetch = 

     See git-config(1) for details.

如果你喜欢练习打字的话, 你可以一直都指定repository (origin) and the branch (v0) ,当你需要pull, push, fetch时:

elisonwu$ git pull origin v0
From file:///home/gitadmin/project1
 * branch            v0       -> FETCH_HEAD
Already up-to-date.


但是有一天,你如果对于每次的输入厌烦了的话,你可以考虑配置下branch,以此来改变这一尴尬局面, 

这里提供两种设置方式:

elisonwu$ git branch --set-upstream v0 origin/v0
Branch v0 set up to track remote branch v0 from origin.

而对于你的git版本早于1.7的版本也可以用

$ git config branch.v0.remote origin
$ git config branch.v0.merge refs/heads/v0

从你决定开始要配置的那一刻开始,你将会感觉到操作是如此的轻松:

      elisonwu$ git pull

   Already up-to-date.

 奉上所有,enjoy it!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值