git设置上游到原点 [英] git set upstream to origin

查看:997
本文介绍了git设置上游到原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读&使用git,但我仍然对来源一词感到困惑。



我有一个本地仓库,并且我在它上面新建了一个分支。这个新的分支是来自我的主人的副本。

我的主人是原始主人的分支,另一个人是由其他人创建的分支,并且在原始主人的前面一些提交和其他一些落后。

我想将我的分支myBranch与原始主合并。即,我希望我的新分支是原始主人(不是我自己的主人)的克隆人。

>

我试过git rebase,git merge,--set-upstream-to =,git fetch ...,说实话我只是感到困惑。 b $ b

解决方案

'origin'只是git给远程仓库的默认名称 - 在你的情况下,你的叉子在github上。如果您愿意,您可以将该名称覆盖为更有意义的内容。 (我经常使用'github'或'bitbucket'而不是'origin')。

您的本地主分支可能正在跟踪远程存储库上的主分支。这将允许您使用

  git checkout master 
推送从主服务器到远程主服务器的更改。git push origin master master

要处理来自新分支的更改,首先需要将它们合并到本地主文件中:

  git checkout master 
git merge mybranch


然后你可以创建一个'拉请求,以便原来的所有者可以将您的更改合并到他们的回购中,如果他们愿意的话。



'$ p
$ b

  git remote add original< url toginal github repo>'将需要添加另一个远程到您的本地存储库:


然后您可以从那里获取更改到您当地的回购:

  git checkout master 
git fetch original
git rebase original / master

并将它们合并到mybranch中,如果您愿意:

  git checkout mybranch 
git rebase master


I have been reading about & using git but am still confused about the term "origin".

I have a local repo and I made a new branch on it. This new branch is a copy from my master.

My master is a fork of the original master, another repo made by someone else, and is ahead of the original master by some commits and behind in some other.

I want to merge my branch "myBranch" with the original master. ie, I want my new branch to be a clone of the original master (not my own master)

How to go?

I have tried git rebase, git merge, --set-upstream-to=, git fetch... and to be honest I'm just confused.

解决方案

'origin' is just the default name given by git to a remote repository - in your case your fork at github. You can override that name to something more meaningful if you wish. (I often use 'github' or 'bitbucket' instead of 'origin').

Your local master branch is probably tracking the master branch on the remote repository. That will allow you to push changes from your master to the remote master using

    git checkout master
    git push origin master

To deal with the changes from your new branch, you need to merge them into your local master first:

    git checkout master
    git merge mybranch

then, you'll be able to push those changes to the remote repo.

You can then create a 'pull request' on github so that the original owner can merge your changes into their repo if they wish.

To bring your fork up to date with changes from the original, you'll need to add another remote to your local repository:

    git remote add original <url to orginal github repo>

then you can fetch changes from there to your local repo:

    git checkout master
    git fetch original
    git rebase original/master

and merge them into mybranch, if you wish:

    git checkout mybranch
    git rebase master

这篇关于git设置上游到原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆