git 添加远程分支

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

git add remote branch

git

提问by Rai

I want to add a remote, and a branch of that remote.

我想添加一个遥控器,以及该遥控器的一个分支。

I did git remote add <newname> <url>, then I did git fetch --allbut git branch -ais not showing any branch of the remote. My .git/config is showing the added remote.

我做了git remote add <newname> <url>,然后我做了,git fetch --allgit branch -a没有显示遥控器的任何分支。我的 .git/config 显示添加的遥控器。

Can anyone please help me out?

任何人都可以帮我吗?

回答by David M. Syzdek

I am not sure if you are trying to create a remote branch from a local branch or vice versa, so I've outlined both scenarios as well as provided information on merging the remote and local branches.

我不确定您是否正在尝试从本地分支创建远程分支,反之亦然,因此我概述了这两种情况,并提供了有关合并远程分支和本地分支的信息。

Creating a remote called "github":

创建一个名为“github”的遥控器:

git remote add github git://github.com/jdoe/coolapp.git
git fetch github

List all remote branches:

列出所有远程分支:

git branch -r
  github/gh-pages
  github/master
  github/next
  github/pu

Create a new local branch (test) from a github's remote branch (pu):

从 github 的远程分支 (pu) 创建一个新的本地分支 (test):

git branch test github/pu
git checkout test

Merge changes from github's remote branch (pu) with local branch (test):

将 github 远程分支 (pu) 的更改与本地分支 (test) 合并:

git fetch github
git checkout test
git merge github/pu

Update github's remote branch (pu) from a local branch (test):

从本地分支(测试)更新 github 的远程分支(pu):

git push github test:pu

Creating a new branch on a remote uses the same syntax as updating a remote branch. For example, create new remote branch (beta) on github from local branch (test):

在远程创建新分支使用与更新远程分支相同的语法。例如,从本地分支(测试)在 github 上创建新的远程分支(测试版):

git push github test:beta

Delete remote branch (pu) from github:

从github删除远程分支(pu):

git push github :pu

回答by Adam Dymitruk

You can check if you got your remote setup right and have the proper permissions with

您可以检查您的远程设置是否正确并具有适当的权限

git ls-remote origin

if you called your remote "origin". If you get an error you probably don't have your security set up correctly such as uploading your public key to github for example. If things are setup correctly, you will get a list of the remote references. Now

如果你称你的远程“原点”。如果您收到错误消息,您可能没有正确设置安全性,例如将您的公钥上传到 github。如果设置正确,您将获得远程引用列表。现在

git fetch origin

will work barring any other issues like an unplugged network cable.

除非出现任何其他问题,如未插入网络电缆,否则将正常工作。

Once you have that done, you can get any branch you want that the above command listed with

完成后,您可以获得上述命令列出的任何您想要的分支

git checkout some-branch

this will create a local branch of the same name as the remote branch and check it out.

这将创建一个与远程分支同名的本地分支并检查它。

回答by Jason

I tested what @Samy Dindane suggested in the comment on the OP.

我测试了@Samy Dindane 在 OP 评论中的建议。

I believe it works, try

我相信它有效,试试

git fetch <remote_name> <remote_branch>:<local_branch>
git checkout <local_branch>

Here's an example for a fictitious remote repository named foowith a branch named barwhere I create a local branch bartracking the remote:

下面是一个虚构的远程存储库的示例,该存储库以foo一个名为的分支命名bar,我在其中创建了一个bar跟踪远程的本地分支:

git fetch foo bar:bar
git checkout bar

回答by Pavan

Here is the complete process to create a local repo and push the changes to new remote branch

这是创建本地存储库并将更改推送到新远程分支的完整过程

  1. Creating local repository:-

    Initially user may have created the local git repository.

    $ git init:- This will make the local folder as Git repository,

  2. Link the remote branch:-

    Now challenge is associate the local git repository with remote masterbranch.

    $ git remote add RepoName RepoURL

    usage: git remote add []

  3. Test the Remote

    $ git remote show--->Display the remote name

    $ git remote -v--->Display the remote branches

  4. Now Push to remote

    $git add .----> Add all the files and folder as git staged'

    $git commit -m "Your Commit Message"- - - >Commit the message

    $git push- - - - >Push the changes to the upstream

  1. 创建本地存储库:-

    最初用户可能已经创建了本地 git 存储库。

    $ git init:- 这将使本地文件夹成为 Git 存储库,

  2. 链接远程分支:-

    现在的挑战是将本地 git 存储库与远程master分支相关联。

    $ git remote add RepoName RepoURL

    用法:git remote add []

  3. 测试遥控器

    $ git remote show--->显示远程名称

    $ git remote -v--->显示远程分支

  4. 现在推送到远程

    $git add .----> 将所有文件和文件夹添加为 git staged'

    $git commit -m "Your Commit Message"- - - >提交消息

    $git push- - - - >将更改推送到上游

回答by Sam Murphy

If the remote branch already exists then you can (probably) get away with..

如果远程分支已经存在,那么你可以(可能)逃脱......

git checkout branch_name

and git will automatically set up to track the remote branch with the same name on origin.

并且 git 将自动设置以跟踪源上具有相同名称的远程分支。