0

I have a topic branch (macaroni), and I have submitted a pull request. I had to make a change after feedback. It was requested that I squash the two commits into a single commit. This is what I have done:

git status
On branch macaroni

git log
commit def  feedback fixes
commit abc  fix cheddar flavor

git rebase -i origin/master
.. go through screen where I pick commit to squash ..
.. go through screen where I update commit message ..

git log
commit abc fix cheddar flavor, squashing done!

at this point I believe I have to push my topic branch using the -force flag, because I have changed history:

git push -f

I am using the second answer from this question:

Preferred Github workflow for updating a pull request after code review

with subtitle "Optional - Cleaning commit history". The author mentions at the end that you should be using topic branches, not sure if I should have changed any of the commands since I'm already on a topic branch.

I am also concerned with accidentally force-pushing something onto the master branch with the above since I'm using -f, but since I'm on the topic branch, only that branch should be affected, right?

Thanks

Community
  • 1
  • 1
user3203425
  • 2,919
  • 4
  • 29
  • 48

3 Answers3

0

check what is going to happen with

git push -f --dry-run

if this looks ok, then do the real command with

git push -f

to see what branch would be affected with a push -f

git branch -vv --list macaroni
Gregg
  • 2,444
  • 1
  • 12
  • 21
  • Ah yes, --dry-run.. ok that gives the following response which I'm not sure about: "fatal: The current branch macaroni has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin macaroni" – user3203425 Jun 09 '16 at 19:35
0

If unsure, use explicit remote name and push spec when force pushing:

git push -f my-remote HEAD:macaroni
jil
  • 2,601
  • 12
  • 14
0

The push command can behave differently depending on you configurations and also the git versions . For example, if you version is 1.X git push defaults to push all matching branches and in your scenario you may have pushed also the master branch.

The variable you need to check is:

push.default

You may find this post useful.

Community
  • 1
  • 1
aeliton
  • 351
  • 4
  • 12