Solution:
The -f
is actually required because of the rebase. Whenever you do a rebase you would need to do a force push because the remote branch cannot be fast-forwarded to your commit. You'd always want to make sure that you do a pull before pushing, but if you don't like to force push to master or dev for that matter, you can create a new branch to push to and then merge or make a PR.
Ensure that your local branch FixForBug is not ahead of the remote branch FixForBug pull and merge the changes before pushing.
git pull origin FixForBug
git push origin FixForBug
In case you want to avoid having to use -f
, then you can use just
git pull
Instead of
git pull --rebase
The non-rebase will fetch the changes from origin/dev
and merge them into your FixForBug
branch. Then, you will be able to run
git push origin FixForBug
without using -f
.
Let's assume the upstream branch is the one that you forked from and origin is your repo and you want to send an MR/PR to the upstream branch.
You already have let's say about 4 commits and you are getting Updates were rejected because the tip of your current branch is behind.
Here is what I did
First, squash all your 4 commits
git rebase -i HEAD~4
You'll get a list of commits with pick
written on them. (opened in an editor)
pick fda59df commit 1
pick x536897 commit 2
pick c01a668 commit 3
pick c011a77 commit 4
To
pick fda59df commit 1
squash x536897 commit 2
squash c01a668 commit 3
squash c011a77 commit 4
After that, you can save your combined commit
Following this
You'll need to stash your commit
git reset --soft HEAD~1
git stash
now rebase with your upstream branch
git fetch upstream beta && git rebase upstream/beta
Now pop your stashed commit
git stash pop
Another way of solution
Let's assume the upstream branch is the one that you forked from and origin is your repo and you want to send an MR/PR to the upstream branch.
You already have let's say about 4 commits and you are getting Updates were rejected because the tip of your current branch is behind.
Here is what I did
First, squash all your 4 commits
git rebase -i HEAD~4
You'll get a list of commits with pick
written on them. (opened in an editor)
example
pick fda59df commit 1
pick x536897 commit 2
pick c01a668 commit 3
pick c011a77 commit 4
to
pick fda59df commit 1
squash x536897 commit 2
squash c01a668 commit 3
squash c011a77 commit 4
After that, you can save your combined commit
Next Move
You'll need to stash your commit
Here's how
git reset --soft HEAD~1
git stash
now rebase with your upstream branch
git fetch upstream beta && git rebase upstream/beta
Now pop your stashed commit
git stash pop
commit these changes and push them
git add -A
git commit -m "[foo] - foobar commit"
git push origin fix/#123 -f