git使用点滴:如何配置branch

http://blog.rexzhao.com/2011/11/22/git-branch.html

Git虽然是分布式的系统,但是小组工作时Git一般都会设置一个中心服务器,大家都往这个服务器上push/pull代码。

有时候需要离开主线(master)做一些测试或者Debug工作,或者想将代码分为开发版、稳定版等,这时候就需要做分支。

在中心服务器这种结构下,所有人的remote端都是这个中心服务器,因此配置方法是(以建立dev分支为例):

  1. 登陆服务器
  2. 执行git branch dev来建立dev分支
  3. 在本地执行git pull来做更新,然后git checkout dev就可以切换到dev分支

另外,git push origin的时候会push所有origin的分支(在只有一个远端的情况下,remote可以不写,因此一般情况下命令是git push ),如果仅仅想push自己所在的某个分支,那么使用git push –f –v –n origin dev

 

Google code: Why 'Everything up-to-date' when pushing (git)

第一次在Google Code上弄项目,注册完毕后,尝试增加一个新文件用以测试Git是否好好工作。结果在Push的时候却显示"Every up-to-date",检查文件时却发现实际上一个都没更新上去。因为对Git不够熟悉,因此只好Googling.

进行一番搜索后找到原因如下:

Why does Git refuse to push, saying "everything up to date"?

git push with no additional arguments only pushes branches that exist in the remote already. If the remote repository is empty, nothing will be pushed. In this case, explicitly specify a branch to push, e.g. git push master.

也就是说一开始git服务器仓库是完全空的,不包含任何一个分支(branch),因此刚开始Push时需要指定一个。

执行git remote -v后看到自己的remote端名字为origin:

$ git remote -v 
origin  https://code.google.com/p/micolog2 (fetch) 
origin  https://code.google.com/p/micolog2 (push)

执行git branch后看到自己当下用的分支是master:

$ git branch 
* master

因此在本地commit后,再执行

git push origin master

即可。

posted @ 2013-02-04 14:08  ArcherDev  阅读(402)  评论(0编辑  收藏  举报