当我希望我的分支始终得到更新时使用Git [英] Using Git when I want my branches to be always updated

查看:110
本文介绍了当我希望我的分支始终得到更新时使用Git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

可以git pull --all更新我所有的本地分支机构?


我是一个快乐的Git用户。但我发现我经常做很多工作,也许这可以实现自动化。



我的意思是,我正在开发一个本地回购站,远程是Github。我有几个分支,比如 master dev bugfixing 。我在多台计算机上工作,所以经常需要从一台计算机上将分支从另一台计算机上拉出来。



这很乏味。这有时会花费很多时间。例如,假设我在 master 上。我可以执行 git pull 并将更新的 origin / master 合并到它中。但后来说 origin / dev 也被更新了。现在我需要 git checkout dev git merge origin / dev ,最后 git checkout master 。这真的很烦人。不要让我开始在这些时间,分支机构没有设置跟踪他们各自的远程分支机构,我必须做 git branch --set-upstream master origin / master



有没有办法让所有分支自动在远程分支中合并?我们可以假设所有的合并都是快进的。 (如果他们不是我没有问题,只是得到一个错误消息,所以我会手动合并。)

解决方案

是不是我想做的事情,但出于兴趣,我写了一个脚本,(我认为)做你想做的:



首先从没有 remote的每个远程更新远程跟踪分支。< name> .skipDefaultUpdate 设为 true 。然后它会遍历你所有的本地分支(即 refs / heads 中的那些分支),并且对于每个拥有上游分支集的分支,转发。如果是这样,它会更新您的分支。



最后,它会尝试将当前分支的上游(如果已设置)合并到当前分支中, git pull



我已经测试了一下,但请注意,由于使用了管道命令 git update-ref 做快进,如果脚本中存在一些错误,那么这可能会很危险,所以没有保证,请仔细测试,了解它在做什么等等。


不要让我开始在这些时间分支机构没有设置跟踪他们各自的远程分支,我必须做的git branch --set-upstream master origin / master


如果您忘记了,那么我得到的唯一问题就是令人困惑的结果包括 master - 一个更简单的方法是使用 git push -u < refspec> 在您推送分店的其中一个场合。


Possible Duplicate:
Can “git pull --all” update all my local branches?

I'm a happy Git user. But I find that I'm often doing a lot of pulling, and maybe this can be automated.

I mean, I'm working on a local repo, and the remote is Github. I have several branches, say master, dev and bugfixing. I work on multiple computers, so often I have to push a branch from one computer and pull it from the other.

This is tedious. This can sometimes take a lot of time. For example, say I'm on master. I can do git pull and have the updated origin/master merged into it. But then say that origin/dev was updated too. Now I need to git checkout dev and git merge origin/dev and finally git checkout master. That's really annoying. And don't get me started on these times where the branches aren't set to track their respective remote branches and I have to do git branch --set-upstream master origin/master.

Is there a way to have all the branches merge in the remote branches automatically? We can assume that all of the merges are fast-forward. (If they aren't I have no problem with just getting an error message so I'll manually merge.)

解决方案

This isn't something I'd want to do myself, but out of interest I've written a script that (I think) does what you want:

This first updates your remote-tracking branches from every remote that doesn't have remote.<name>.skipDefaultUpdate set to true. Then it goes through all of your local branches (i.e. those under refs/heads) and for each one that has an upstream branch set, sees if your local branch can be fast-forwarded. If so, it updates your branch.

Finally, it tries to merge the upstream for your current branch (if it is set) into the current branch, as would happen with git pull.

I've tested this a bit, but note that because of the use of the plumbing command git update-ref to do the fast-forward, it's potentially dangerous if there's some bug in the script, so no warranties, please test carefully, understand what it's doing, etc.

And don't get me started on these times where the branches aren't set to track their respective remote branches and I have to do git branch --set-upstream master origin/master

The only problem I have with that command is the really confusing results if you forget to include master - an easier alternative is to use git push -u <remote-name> <refspec> on one of the occasions when you push the branch.

这篇关于当我希望我的分支始终得到更新时使用Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆