[英]Is it safe to do a git pull from master to my local repo after creating a new branch on which I need to see the latest changes too?
I would like to have the latest updates from the remote repo on my local one. 我想从本地本地的远程仓库获取最新的更新。 I usually do git pull while being on the master branch and then create a new branch.
我通常在master分支上时进行git pull,然后创建一个新分支。 I have now created a new branch (did not add/change anything in the local code) but skipped the git pull on master before this.
我现在创建了一个新分支(未在本地代码中添加/更改任何内容),但是在此之前跳过了master上的git pull。 If I do a git pull, will the latest remote modifications be reflected on my new local branch and local master, or should I delete it and recreate it after git pull?
如果我进行git pull,最新的远程修改会反映在新的本地分支和本地master上,还是应该删除它并在git pull之后重新创建它? Thanks!
谢谢!
What git will do depends on the exact command you issue, and also on your git configuration. git的作用取决于您发出的确切命令以及git的配置。
The first thing to understand about pull
is, it updates the current branch. 了解
pull
的第一件事是,它会更新当前分支。 If you check out master
and then pull
, the changes you pull will be incorporated into master
(but not your branch). 如果先签出
master
,然后再pull
,那么您所做的更改将并入master
(但不包含在您的分支中)。 If you check out your branch and then pull
, the changes will be incorporated into your branch (but not master
). 如果您签出分支,然后
pull
,则pull
的更改将合并到分支中(但不是master
)。 This, of course, is the point of branching - changes to one branch don't automatically affect the other. 当然,这是分支的重点-对一个分支的更改不会自动影响另一个分支。 If you want to affect both, you can (see below for more on that).
如果您想同时影响这两者,则可以(有关更多信息,请参见下文)。
Also, you can tell git what changes to incorporate into the current branch, or if you don't specify then it will look for a configured default corresponding to the current branch. 另外,您可以告诉git将哪些更改合并到当前分支中,或者,如果不指定,它将寻找与当前分支相对应的已配置默认值。 (Some people seem to think this default behavior is all
pull
does, and that can get them into trouble.) So if you want to integrate the remote master
's changes into your branch, you can do (有些人似乎认为此默认行为是
pull
所做的,这可能会使他们陷入麻烦。)因此,如果要将远程master
的更改集成到分支中,则可以执行
git checkout my_branch
git pull origin master
I typically don't recommend this usage. 我通常不推荐这种用法。 It's basically a shorthand for
这基本上是
git checkout my_branch
git fetch
git merge origin/master
which is a little more explicit (so less dependent on configuration details, etc.). 这更加明确(因此对配置细节的依赖性降低了,等等)。 I use
pull
quite a bit, but only for its default behavior in repos whose configuration/branch setup is "typical". 我使用了
pull
相当多的功能,但仅用于其在配置/分支设置为“典型”的回购协议中的默认行为。
Now, if you want the origin/master
changes reflected in multiple branches, then you have to perform multiple merge (and/or rebase) operations; 现在,如果您希望
origin/master
更改反映在多个分支中,则必须执行多个合并(和/或变基)操作; and a given pull
only does one. 一个给定的
pull
只会做一个。 So typically you'd first get the changes into your local master
因此通常情况下,您首先需要将更改输入到本地
master
git checkout master
git pull
(or, depending on configuration, maybe you'd need git pull origin
or even git pull origin master
). (或者,根据配置,也许您需要
git pull origin
甚至git pull origin master
)。 Then you'd incorporate them into the branch by either 然后,您可以将它们合并到分支中
git checkout my_branch
git merge master
or 要么
git rebase master my_branch
Git will try to merge the remote master to your lokal new branch. Git将尝试将远程主服务器合并到您的新分支。 Since you have no changes you will just get the current remote master to your branch.
由于您没有任何更改,因此只需将当前的远程主服务器添加到您的分支即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.