git自动获取定期/分支结帐 [英] Git automatic fetch periodically/on branch checkout
问题描述
我想要一些自动化的方法来从我们的远程原始服务器获取数据. 因此,也许每次我切换分支时,git都会在切换之前自动对所有来自起源的分支进行提取...这样,当我从本地修复分支"移至母版时,它会告诉我我的母版位于原版母版的后面.
I would like some automated method to do a fetch from our remote origin server. So perhaps every time I switch branches git would automatically do a fetch on all branches from origin before the switch... this way when I move from a local "fix branch" to master it would tell me that my master is behind origin master.
这可能吗?如果您需要了解我为什么要这样做,则更详细的原因如下.
Is this possible? A more detailed reason for my requirement is below if you need to know why I want this.
谢谢大家!
我在一个开发人员团队中工作.当我向origin/master分支添加更改时,我还将该更改上传到我们的FTP服务器(我们尚未在服务器上设置git)
I work in a team of developers. When I add a change to our origin/master branch I also upload that change to our FTP server (we have not yet setup git on our server)
如果我创建一个修复分支"并对文件进行更改...那么我想使这些文件生效并成为主文件.如果仅将本地文件中的更改合并到本地主机中而不进行获取,则可能会导致问题. 如果在上载文件之前忘记从原产地进行更改,则我可能正在上传原产地缺少修订的文件. (我知道这很调皮)
If I create a "fix branch" and make changes to a file... Then I want to get these files live and into master. If I simply merge the changes in my local file into my local master without a fetch this could cause problems. if I forget to bring in changes from our origin prior to upload the file I may be uploading the file with missing revisions from origin. (naughty I know)
我还想尽快了解主服务器中的任何更新,以便将其合并到我的修复分支"中.
Also I would like to be aware of any updates in the master as soon as possible so that I can incorporate them into my "fix branch"
推荐答案
一种选择是使用git别名:
One option is to use a git alias:
git config --global alias.co "!f() { git fetch && git checkout $1; }; f"
如果您使用git co <branch>
之类的别名,它将在结帐前进行访存. (感谢带有位置参数的Git别名,用于演示如何执行此操作)
If you use the alias like git co <branch>
, it'll do a fetch before checkout. (Thanks to Git alias with positional parameters for demonstrating how to do this)
这篇关于git自动获取定期/分支结帐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!