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

本文探讨了Git推送操作的优化方法,包括如何配置`push.default`以避免代码冲突,以及使用`git fetch`和`git pull`进行版本同步的最佳实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 则会强制更新合并到本地
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值