`

2013.11.14(2) ——— git学习之提交远程库

 
阅读更多
2013.11.14(2) ——— git学习之提交远程库

git push 远端库名称  本地分支名称 :远程分支的名称

git push origin dev:dev


每次这样很麻烦,可以简化为
git push

但是 git里面有一个全局变量可以控制这个push的方式

如果执行
git push

会有什么后果呢

git2.0之前 会提交所有的分支
git2.0 只会提交本分支,并且分支名字一样

push.default

Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:

nothing - do not push anything.
matching - push all branches having the same name in both ends. This is for those who prepare all the branches into a publishable shape and then push them out with a single command. It is not appropriate for pushing into a repository shared by multiple users, since locally stalled branches will attempt a non-fast forward push if other users updated the branch. 
This is currently the default, but Git 2.0 will change the default to simple.
upstream - push the current branch to its upstream branch. With this, git push will update the same remote ref as the one which is merged by git pull, making push and pull symmetrical. See "branch.<name>.merge" for how to configure the upstream branch.
simple - like upstream, but refuses to push if the upstream branch’s name is different from the local one. This is the safest option and is well-suited for beginners. It will become the default in Git 2.0.
current - push the current branch to a branch of the same name.
The simple, current and upstream modes are for those who want to push out a single branch after finishing work, even when the other branches are not yet ready to be pushed out. If you are working with other people to push into the same shared repository, you would want to use one of these.


大体意思是:

nothing:不推任何东西(要来做什么用?)。
matching:将两边名字能匹配的分支推上去。
upstream:将当前分支推到它的upstream分支。
simple:将当前分支推到它的upstream分支,但名字不匹配时拒绝。这是最安全的选项并且git 2.0之后会默认为这个。
current:将当前分支推到与它同名的分支上。


所以想要用git push的话 就设置一下
git config --global push.default simple




每次提交前,最好都执行
git fetch 
git rebase



这样防止代码冲突,类似于svn的先update后commit


git fetch 和 git pull

git fetch 是把更新了本地分支,但是没有合并 rebase的时候 才会尝试合并
git pull 则会强制更新合并到本地



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics