简体   繁体   English

在创建新分支后也需要从master到本地本地仓库的git pull安全吗?我也需要在该分支上查看最新更改?

[英]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.

相关问题 我是否必须“拉”将最新的内容合并到我的本地分支中? - Do I have to 'pull' to merge the latest into my local branch in git? 如何在每次从master下拉之后对git repo应用本地更改,而不必推送到master - How to apply local changes to git repo after every pull from master without ever pushing to master 如何获取具有最新更改的不同存储库并将我的更新也保留在 git 上? - How can I pull in a different repo with the latest changes and keep my updates too on git? 撤消来自master的git pull,通过本地更改使repo进入状态 - Undo git pull from master, bring repo to state with local changes Git-创建本地分支后拉原点主机 - Git - pull origin master after creating local branch 如何从本地主机(而不是已删除的分支)中提取本地存储库? - How to have my local repo pull from master, not a deleted branch? Git-拉取请求后,我的本地master分支会怎样? 如何管理多个进行中的分支? - Git - What happens to my local master branch after a pull request? How do I manage multiple in progress branches? git pull 后 master 之前的本地分支 - Local branch ahead of master after git pull Git:当创建没有提交的新分支时,对master的更改也会更改分支 - Git: When creating a new branch without commit, changes to master changes branch too 在Git中将本地仓库从主仓库切换到分支机构 - Switch local repo from master to branch in Git
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM