git - 从特定分支拉取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4924002/
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 10:03:16  来源:igfitidea点击:

git - pulling from specific branch

git

提问by Alex

I have cloned a git repository to my dev server and then switched to the dev branch but now I can't do a git pull to update the branch.

我已将 git 存储库克隆到我的开发服务器,然后切换到开发分支,但现在我无法执行 git pull 来更新分支。

How do I update the code on the server ?

如何更新服务器上的代码?

回答by Cascabel

See the git-pull man page:

请参阅git-pull 手册页

git pull [options] [<repository> [<refspec>...]]

git pull [options] [<repository> [<refspec>...]]

and in the examples section:

并在示例部分:

Merge into the current branch the remote branch next:

$ git pull origin next

接下来将远程分支合并到当前分支中:

$ git pull origin next

So I imagine you want to do something like:

所以我想你想做这样的事情:

git pull origin dev

To set it up so that it does this by default while you're on the dev branch:

要设置它以便它在您在 dev 分支时默认执行此操作:

git branch --set-upstream-to dev origin/dev

回答by thestar

Here is what you need to do. First make sure you are in branch that you don't want to pull. For example if you have master and develop branch, and you are trying to pull develop branch then stay in master branch.

这是您需要做的。首先确保你在你不想拉的分支中。例如,如果您有 master 和 develop 分支,并且您尝试拉取 develop 分支,则留在 master 分支。

git checkout master

Then,

然后,

git pull origin develop

回答by wnoise

It's often clearer to separate the two actions git pulldoes. The first thing it does is update the local tracking branc that corresponds to the remote branch. This can be done with git fetch. The second is that it then merges in changes, which can of course be done with git merge, though other options such as git rebaseare occasionally useful.

将这两个动作分开通常会更清楚git pull。它做的第一件事是更新与远程分支对应的本地跟踪分支。这可以通过git fetch. 第二个是它然后合并更改,这当然可以用 来完成git merge,尽管其他选项(例如)git rebase偶尔有用。

回答by Erich García

Laravel documentation example:

Laravel 文档示例:

git pull https://github.com/laravel/docs.git 5.8

based on the command format:

基于命令格式:

git pull origin <branch>

回答by vikas etagi

Here are the steps to pull a specific or any branch,

以下是拉取特定分支或任何分支的步骤,

1.clone the master(you need to provide username and password)

1.clone master(需要提供用户名和密码)

       git clone <url>

2. the above command will clone the repository and you will be master branch now

2.上面的命令将克隆存储库,您现在将成为主分支

       git checkout <branch which is present in the remote repository(origin)>

3. The above command will checkout to the branch you want to pull and will be set to automatically track that branch

3. 上面的命令会checkout到你要拉取的分支,并设置为自动跟踪那个分支

4.If for some reason it does not work like that, after checking out to that branch in your local system, just run the below command

4.如果由于某种原因它不能那样工作,在您本地系统中签出该分支后,只需运行以下命令

       git pull origin <branch>

回答by Nikunj K.

You can take update / pull on git branch you can use below command

您可以在 git 分支上进行更新/拉取,您可以使用以下命令

git pull origin <branch-name>

The above command will take an update/pull from giving branch name

上面的命令将从提供分支名称中进行更新/拉取

If you want to take pull from another branch, you need to go to that branch.

如果你想从另一个分支拉取,你需要去那个分支。

git checkout master

Than

git pull origin development

Hope that will work for you

希望这对你有用

回答by sesha

git-pull - Fetch from and integrate with another repository or a local branch

git-pull - 从另一个存储库或本地分支获取并集成

git pull [options] [<repository> [<refspec>...]]

git pull [options] [<repository> [<refspec>...]]

You can refer official git doc https://git-scm.com/docs/git-pull

你可以参考官方 git doc https://git-scm.com/docs/git-pull

Ex :

前任 :

git pull origin dev

git pull origin dev

回答by Ali Hassan

if you want to pull from a specific branch all you have to do is

如果你想从一个特定的分支中拉取,你所要做的就是

git pull 'remote_name' 'branch_name'

NOTE: Make sure you commit your code first.

注意:确保首先提交代码。