Restore a local Git branch before clicking on a remote

Remote controls: origin

$ git branch * master $ git checkout -b "new_feature" 

Now I make a couple of commits on the "new_feature" branch and want to update it to origin after that.

 $ git branch master * new _feature $ git pull --rebase origin new_feature $ git push origin new_feature 

Is this the right way to update the local branch before clicking on the remote?

+6
source share
2 answers

Do you want to use

 git pull --rebase origin master 

git pull arguments must be optional remote and optional refspec or reference / branch on this remote :

 git pull [options] [<repository> [<refspec>โ€ฆ]] 

new_feature will not work because it is a local branch, and in addition, it does not make sense for rebase , because you want to pass the revision to the rebase branch on top . If you checked new_feature , then he understood / implied that the branch you want to use rebase usually works rebase .

+3
source

After creating the branch "new_feature" you will have a state like

 o <master> <origin/master> <new_feature> most recent commit | ... 

Then, after making changes to your local branch, your repository will look like

 o <new_feature> your last commit | o your first commit | o <master> <origin/master> most recent commit | ... 

Performance

 git pull --rebase origin master 

as Cupcake suggests, you're done with

 o <new_feature> your last commit | o your first commit | o <origin/master> something meanwhile commited on remote master | o <master> most recent commit | ... 

your changes are rebuilt on top of "origin / master". These are not your initial commits, but they make changes to match the โ€œnewโ€ โ€œorigin / masterโ€.

When reinstalling, you may get merge conflicts, because changes made on the remote host may conflict with your changes.

But since "new_feature" is now "on top" of "origin / master", you can click on the remote master.

This will also move the tag "origin / master" to the level of "new_feature". If you also want your local master to be on the go, you should check it and merge with origin / master.

0
source

Source: https://habr.com/ru/post/953105/


All Articles