我创建了一个本地分支。如何将其推送到远程服务器?

更新:我在这里为Git2.0写了一个更简单的答案。


当前回答

你可以简单地,

git结帐-b YOUR-NEW-BRANCH-NAMEgit添加。git推送原点YOUR-NEW-BRANCH-NAME

您可以在相关git repo下看到您的分行代码

干杯!!:)

其他回答

如果已使用--single branch克隆当前分支,请使用此命令从当前分支创建新分支:

git checkout -b <new-branch-name>
git push -u origin <new-branch-name>
git remote set-branches origin --add <new-branch-name>
git fetch

从现有分支创建本地分支(可以是主分支/开发分支/任何其他分支)。

git checkout-b分支名称

将此推送到远程

git push-u remote_name local_branch_name:remote_branch-name

在这里

-u:设置上游分支remote_name:git在创建存储库时默认将名称设置为“origin”。但是,可以将其更改为其他任意名称。local_branch_name:是要推送的本地分支的名称。remotebranch_name:是要在远程上创建的远程分支的名称。

如果我们删除本地和远程分支名称,它将具有以下格式

git push-u remote_name分支名称

这将将本地分支推送到远程,并使用与本地分支branch_name相同的名称。本地分支也将跟踪远程分支。

从Git2.37.0开始,您不再需要“--setupstreamorigin”。只要按一下。您可以通过启用push.autoSetupRemote选项来实现这一点

git-config--global--add--bool push.autoSetupRemote true

如前面的回答中所述,

git push <remote-name> <local-branch-name>:<remote-branch-name>

足以推动本地分支。

您的同事可以使用以下命令拉动所有远程分支(包括新分支):

git remote update

然后,要对分支进行更改,通常的流程如下:

git checkout -b <local-branch-name> <remote-name>/<remote-branch-name>

我用这个,它很方便:

git config --global alias.mkdir '!git checkout -b $1; git status; git push -u origin $1; exit;'

用法:git mkdir NEW_BRANCH

你甚至不需要git状态;也许,我只是想确保一切顺利。。。

您可以通过一个命令同时拥有LOCAL和REMOTE分支。