git 使用 GitHub 存储库中的更改更新本地存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1443210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:04:37  来源:igfitidea点击:

Updating a local repository with changes from a GitHub repository

gitgithub

提问by Tom

I've got a project checked locally from GitHub, and that remote repository has since had changes made to it. What's the correct command to update my local copy with the latest changes?

我从 GitHub 本地检查了一个项目,并且该远程存储库已经对其进行了更改。使用最新更改更新我的本地副本的正确命令是什么?

回答by James Healy

Probably:

大概:

git pull origin master

回答by Andrzej Rehmann

This should work for every default repo:

这应该适用于每个默认回购:

git pull origin master

If your default branch is different than master, you will need to specify the branch name:

如果您的默认分支不同于master,则需要指定分支名称:

git pull origin my_default_branch_name

回答by Gareth

git fetch [remotename]

However you'll need to merge any changes into your local branches. If you're on a branch that's tracking a remote branch on Github, then

但是,您需要将任何更改合并到本地分支中。如果您在跟踪 Github 上远程分支的分支上,那么

git pull

will first do a fetch, and then merge in the tracked branch

将首先执行 fetch,然后在被跟踪的分支中合并

回答by Mahavir Chhasatiya

This question is very general and there are a couple of assumptions I'll make to simplify it a bit. We'll assume that you want to update your masterbranch.

这个问题很笼统,我会做一些假设来简化它。我们假设您想更新您的master分支。

If you haven't made any changes locally, you can use git pullto bring down any new commits and add them to your master.

如果您没有在本地进行任何更改,您可以使用git pull来取消任何新提交并将它们添加到您的master.

git pull origin master

If you have made changes, and you want to avoid adding a new merge commit, use git pull --rebase.

如果您进行了更改,并且希望避免添加新的合并提交,请使用git pull --rebase.

git pull --rebase origin master

git pull --rebasewill work even if you haven't made changes and is probably your best call.

git pull --rebase即使您没有进行更改也将起作用,并且可能是您最好的选择。

回答by Shailendra

With an already-set origin master, you just have to use the below command -

使用已经设置的原点大师,您只需要使用以下命令 -

git pull "https://github.com/yourUserName/yourRepo.git"