How to rebase both locally and remotely?

81 views Asked by At

enter image description here

The orange shows the local branch, the yellow shows the remote branch.

I rebased my branch locally. Then to push the changes to remote, I performed a pull (because it had informed me that my branch is now behind), and then a push. Am I supposed to do a force push? Or delete remote and then push?

Since the two branches are now "merged", is my best course of action to perform a reset/delete of the merge, delete the remote branch, and then push again?

1

There are 1 answers

0
mfnx On

Say you have a branch master and a branch feature which starts from some commit on master. Then, you push that branch on the remote:

git checkout master
git checkout -b feature
/* do some stuff, commits, etc */
git push origin feature

Next, a collegue of yours commits on master. You would like to have those changes in your branch feature, and therefore you decide to do:

git checkout master
git pull origin master

git checkout feature
git rebase master

If then you want to push that feature branch onto the remote so it looks identical as your local repository, you need the force flag:

git push -f origin feature

Whether or not this is good practice is another question. You could push it to another branch, as you said for example. With git, there are always many options.