假设有人创建了一个分支xyz。如何从远程服务器(例如GitHub)中提取分支xyz并将其合并到本地存储库中的现有分支xyz中?

答案推送分支到Git会给我一个错误“![拒绝]”,并提到“非快进”。


当前回答

你可以试试

git branch -a

或gitfetch获取最新的分支列表。

git签出分行//进入分行

gitcheckout-b“yourNewBranch”//在基本“theBranch”中的自己的分支中工作

其他回答

这有助于我在将其合并到其他分支之前获取远程分支:

git fetch repo xyz:xyz
git checkout xyz

一种安全的方法是首先创建本地分支(即xyz),然后将远程分支拉入本地。

# create a local branch
git checkout -b xyz

# make sure you are on the newly created branch
git branch

# finally pull the remote branch to your local branch
git pull origin xyz

下面是可以将远程分支拉到本地分支的语法。

git pull {repo} {remotebranchname}:{localbranchname}

git pull origin xyz:xyz

这些对我有用。

要将特定的远程分支拉到当前所在的本地分支,请执行以下操作。(其中<remote_repo>是远程存储库,<remote_branch>是您要拉取的特定远程分支)

git pull <remote_repo> <remote_branch>

e.g.

git pull origin remote_master

将特定远程分支拉到特定本地分支。(其中<local_branch>是您要拉入的特定本地分支)

git pull <remote_repo> <remote_branch>:<local_branch>

e.g.

git pull origin remote_master:local_master
git pull <gitreponame> <branchname>

通常,如果您只有repo分配给代码,那么gitrepname将是源代码。

如果您正在处理两个回购,比如一个是本地的,另一个是远程的,您可以从gitremote-v查看回购列表。这显示了分配给当前代码的回购数量。

BranchName应存在于相应的gitrepname中。

您可以使用以下两个命令添加或删除repo

git remote add <gitreponame> <repourl>
git remote remove <gitreponame>

可以使用

git checkout --track origin/the-branch-name

确保分支名称完全相同。