For safety reason, my supervisor doesn't allow me to pull his work directly from the master branch. So I created one branch remotely named 'subbranch' and clone it to my local repository. How could I let 'subbranch' keep up to date with the master branch? I just know how to use the GUI to do it. How to do it with command line?
出于安全原因,我的主管不允许我直接从主分支机构提取他的工作。所以我创建了一个远程命名为“subbranch”的分支,并将其克隆到我的本地存储库。我怎么能让'subbranch'与主分支保持同步?我只知道如何使用GUI来做到这一点。如何用命令行完成?
2 个解决方案
#1
If you have not done it already clone the repository from master and then create a local branch in your clone, tracking to your upstream branch. For example
如果尚未完成,则已从master中克隆存储库,然后在克隆中创建本地分支,并跟踪到上游分支。例如
git clone https://github.com/rgulia/myclone
cd myclone
git checkout -b subbranch origin/subbranch
When you need to work in your clone, make sure you are on your branch.
当您需要在克隆中工作时,请确保您在分支机构中。
git branch # your current branch is highlighted with a '*'
Work on your branch normally, by committing changes to your branch. Push changes to your remote branch.
通常,通过对您的分支进行更改来在您的分支上工作。将更改推送到远程分支。
git commit
git push origin subbranch
From time to time you want to update with the changes from master
您有时希望使用master中的更改进行更新
git fetch # get the changes from the remote repository.
git merge master # merge them into your branch
git push origin subbranch # push your changes upstream
The git fetch applies to all branches, including master. The git merge creates a commit in your branch. Since you always work in your branch, you never commit nor push to master.
git fetch适用于所有分支,包括master。 git merge在您的分支中创建一个提交。因为你总是在你的分支机构工作,所以你永远不会提交或推动掌握。
You might have to resolve conflicts. See this excellent tutorial. http://www.vogella.com/tutorials/Git/article.html#mergeconflict
您可能必须解决冲突。看到这个优秀的教程。 http://www.vogella.com/tutorials/Git/article.html#mergeconflict
I hope this helps.
我希望这有帮助。
#2
git branch --set-upstream-to remote-branch # to track your local branch with remote branch
git branch --set-upstream-to remote-branch#用远程分支跟踪你的本地分支
git pull --rebase # to get the latest changes of remote branch
git pull --rebase#来获取远程分支的最新变化
#1
If you have not done it already clone the repository from master and then create a local branch in your clone, tracking to your upstream branch. For example
如果尚未完成,则已从master中克隆存储库,然后在克隆中创建本地分支,并跟踪到上游分支。例如
git clone https://github.com/rgulia/myclone
cd myclone
git checkout -b subbranch origin/subbranch
When you need to work in your clone, make sure you are on your branch.
当您需要在克隆中工作时,请确保您在分支机构中。
git branch # your current branch is highlighted with a '*'
Work on your branch normally, by committing changes to your branch. Push changes to your remote branch.
通常,通过对您的分支进行更改来在您的分支上工作。将更改推送到远程分支。
git commit
git push origin subbranch
From time to time you want to update with the changes from master
您有时希望使用master中的更改进行更新
git fetch # get the changes from the remote repository.
git merge master # merge them into your branch
git push origin subbranch # push your changes upstream
The git fetch applies to all branches, including master. The git merge creates a commit in your branch. Since you always work in your branch, you never commit nor push to master.
git fetch适用于所有分支,包括master。 git merge在您的分支中创建一个提交。因为你总是在你的分支机构工作,所以你永远不会提交或推动掌握。
You might have to resolve conflicts. See this excellent tutorial. http://www.vogella.com/tutorials/Git/article.html#mergeconflict
您可能必须解决冲突。看到这个优秀的教程。 http://www.vogella.com/tutorials/Git/article.html#mergeconflict
I hope this helps.
我希望这有帮助。
#2
git branch --set-upstream-to remote-branch # to track your local branch with remote branch
git branch --set-upstream-to remote-branch#用远程分支跟踪你的本地分支
git pull --rebase # to get the latest changes of remote branch
git pull --rebase#来获取远程分支的最新变化