如何使用远程主服务器重新建立本地分支

本文翻译自:How to rebase local branch with remote master

I have cloned project from master branch from remote repository remote_repo . 我已经从远程存储库remote_repo master分支中克隆了项目。 I create new branch and I commit to that branch. 我创建一个新分支,然后提交该分支。 Other programmers pushed to remote_repo to master branch. 其他程序员将remote_repo推送到master分支。 I need now to rebase my branch RB onto remote_repo master. 现在,我需要将分支RB重新建立到remote_repo主服务器上。 How to do this ? 这个怎么做 ? What commands to type to terminal ? 在终端输入什么命令?


#1楼

参考:https://stackoom.com/question/XGn3/如何使用远程主服务器重新建立本地分支


#2楼

git pull --rebase origin master
# where --rebase[=(false|true|merges|preserve|interactive)]

#3楼

Note: If you have broad knowledge already about rebase then use below one liner for fast rebase. 注意:如果您已经具备有关变基的广泛知识,那么请使用一根以下的衬纸进行快速变基。 Solution: Assuming you are on your working branch and you are the only person working on it. 解决方案:假设您在工作分支上,并且您是唯一在该分支上工作的人。

git fetch && git rebase origin/master

Resolve any conflicts, test your code, commit and push new changes to remote branch. 解决所有冲突,测试您的代码,提交并将新更改推送到远程分支。

                            ~:   For noobs   :~

The following steps might help anyone who are new to git rebase and wanted to do it without hassle 以下步骤可能会帮助git rebase新手并希望轻松完成此操作

Step 1: Assuming that there are no commits and changes to be made on YourBranch at this point. 步骤1:假设此时没有在YourBranch上进行提交和更改。 We are visiting YourBranch. 我们正在访问YourBranch。

git checkout YourBranch
git pull --rebase

What happened? 发生了什么? Pulls all changes made by other developers working on your branch and rebases your changes on top of it. 提取分支上其他开发人员所做的所有更改,并在此基础上重新进行更改。

Step 2: Resolve any conflicts that presents. 步骤2:解决出现的任何冲突。

Step 3: 第三步:

git checkout master
git pull --rebase

What happened? 发生了什么? Pulls all the latest changes from remote master and rebases local master on remote master. 从远程主机上提取所有最新更改,并在远程主机上重新建立本地主机的基础。 I always keep remote master clean and release ready! 我总是保持远程主机干净并准备发布! And, prefer only to work on master or branches locally. 并且,只希望在本地的master或分支上工作。 I recommend in doing this until you gets a hand on git changes or commits. 我建议您这样做,直到您对git进行更改或提交为止。 Note: This step is not needed if you are not maintaining local master, instead you can do a fetch and rebase remote master directly on local branch directly. 注意:如果您不维护本地主服务器,则不需要此步骤,而是可以直接在本地分支上进行获取和重新设置远程主服务器的基准。 As I mentioned in single step in the start. 正如我在一开始提到的那样。

Step 4: Resolve any conflicts that presents. 步骤4:解决出现的任何冲突。

Step 5: 步骤5:

git checkout YourBranch
git rebase master

What happened? 发生了什么? Rebase on master happens 依靠大师发生

Step 6: Resolve any conflicts, if there are conflicts. 步骤6:解决任何冲突(如果存在冲突)。 Use git rebase --continue to continue rebase after adding the resolved conflicts. 添加已解决的冲突后,请使用git rebase --continue继续进行重新设置。 At any time you can use git rebase --abort to abort the rebase. 您可以随时使用git rebase --abort中止rebase。

Step 7: 步骤7:

git push --force-with-lease 

What happened? 发生了什么? Pushing changes to your remote YourBranch. 将更改推送到您的远程YourBranch。 --force-with-lease will make sure whether there are any other incoming changes for YourBranch from other developers while you rebasing. --force-with-lease将确保您在重新定基础时,YourBranch是否从其他开发人员收到其他任何更改。 This is super useful rather than force push. 这是超级有用的方法,而不是强行推动。 In case any incoming changes then fetch them to update your local YourBranch before pushing changes. 如果有任何传入的更改,则在推送更改之前先获取它们以更新您的本地YourBranch。

Why do I need to push changes? 为什么我需要推动变更? To rewrite the commit message in remote YourBranch after proper rebase or If there are any conflicts resolved? 要在正确调整基准后在远程YourBranch中重写提交消息,或者是否解决了任何冲突? Then you need to push the changes you resolved in local repo to the remote repo of YourBranch 然后,您需要将在本地存储库中解决的更改推送到YourBranch的远程存储库中

Yahoooo...! Yahoooo ...! You are succesfully done with rebasing. 您已经成功完成了基础调整。

You might also be looking into doing: 您可能还会考虑这样做:

git checkout master
git merge YourBranch

When and Why? 什么时候以及为什么? Merge your branch into master if done with changes by you and other co-developers. 如果您和其他共同开发人员进行了更改,则将分支合并到master。 Which makes YourBranch up-to-date with master when you wanted to work on same branch later. 当您以后想要在同一个分支上工作时,这可以使YourBranch与master保持最新。

                            ~:   (๑ơ ₃ ơ)♥ rebase   :~

#4楼

git fetch origin master:master pulls the latest version of master without needing to check it out. git fetch origin master:master不需要检出最新版本的master。

So all you need is: 因此,您需要做的是:

git fetch origin master:master && git rebase master git fetch origin master:master && git rebase master master


#5楼

1.Update Master first... 1.先更新Master ...

git checkout [master branch]
git pull [master branch]

2.Now rebase source-branch with master branch 2.现在使用master分支对源分支进行重新设置

git checkout [source branch]
git rebase [master branch]
git pull [source branch] (remote/source branch)
git push [source branch]

IF source branch does not yet exist on remote then do: 如果远程上尚不存在源分支,请执行以下操作:

git push -u origin [source branch]

"et voila..." “等等!”


#6楼

Step 1: 第1步:

git fetch origin

Step 2: 第2步:

git rebase origin/master

Step 3:(Fix if any conflicts) 第3步:(解决任何冲突)

git add .

Step 4: 第四步:

git rebase --continue

Step 5: 步骤5:

git push --force

你可能感兴趣的:(如何使用远程主服务器重新建立本地分支)