如何将本地分支推送到github的一个分支?(本地分支不是克隆的,而是创建的)
我在本地机器中有两个分支,即master和firstbranch。我在github存储库中有两个分支,即master和firstbranch_1。现在我想从我的localbranch(firstbranch)推送到branch firstbranch_1的远程存储库。我应该怎么做?注意:我没有从github克隆任何东西。我首先在本地机器上创建了它,并将其推送到repo中,然后在github中创建了一个分支。只需推即可。如果分支不相关,那么您可能必须强制执行它如何将本地分支推送到github的一个分支?(本地分支不是克隆的,而是创建的),git,github,Git,Github,我在本地机器中有两个分支,即master和firstbranch。我在github存储库中有两个分支,即master和firstbranch_1。现在我想从我的localbranch(firstbranch)推送到branch firstbranch_1的远程存储库。我应该怎么做?注意:我没有从github克隆任何东西。我首先在本地机器上创建了它,并将其推送到repo中,然后在github中创建了一个分支。只需推即可。如果分支不相关,那么您可能必须强制执行它 git push origin fi
git push origin firstbranch:firstbranch_1
(假设远程调用origin)将本地分支推送到GitHub
需要使用--set upstream
标志“连接”本地和远程分支,因此origin/firstbranch
将显示在您的Git日志中,Git status
将显示
Your branch is ahead/behind 'origin/firstbranch' by XY commits
如果本地分支和远程分支不同,则显示消息(因此需要推送
/拉送
)
从GitHub“克隆”(获取)分支
这将“克隆”分支,并创建一个本地firstbranch\u 1
,连接到远程分支
刚刚意识到,我误解了你的问题。要连接本地
firstbranch
和远程firstbranch\u 1
,请使用
$ git push origin firstbranch:firstbranch_1
但如果两个分支不同,此命令将失败:
To https://github.com/whatever/repo.git
! [rejected] firstbranch -> firstbranch_1 (non-fast-forward)
error: failed to push some refs to 'https://github.com/whatever/repo.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
如果你想
将远程分支替换为本地分支
这将强制推送,远程firstbranch_1
将替换为本地firstbranch
的提交
将本地分支替换为远程分支
这将删除本地firstbranch
的更改,并将其尖端移动到远程firstbranch\u 1
在远程分支上重新设置本地分支的基础
这将保留提交的firstbranch\u 1
,并在其上应用firstbranch
。可能重复的
$ git push origin firstbranch:firstbranch_1
To https://github.com/whatever/repo.git
! [rejected] firstbranch -> firstbranch_1 (non-fast-forward)
error: failed to push some refs to 'https://github.com/whatever/repo.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git push --force-with-lease origin firstbranch:firstbranch_1
$ git checkout firstbranch
$ git reset --hard origin/firstbranch_1
$ git rebase origin/firstbranch_1 firstbranch