1

I would like to create a pull request for a branch (uglyCommitsBranch) that I have, but it has lots of commit messages I would like to squeeze into one commit.
To do so, I think the following steps need to happen:

git checkout master
git pull
git branch newFeature
git push origin newFeature
git checkout newFeature

Now I need to take stuff from uglyCommitsBranch and put them all into newFeature, then push to origin for code review.

What are the next commands I need to run?
I am not sure how to run rebase commands and am afraid of breaking master.

If I am currently on newFeature branch (clean branch off master), what are the next commands to get this done?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Cmag
  • 14,946
  • 25
  • 89
  • 140
  • Note: I have amended my answer in light of the new workflow described in http://stackoverflow.com/a/36377634/6309. – VonC Apr 02 '16 at 19:24

1 Answers1

1

You don't need to do that:

Simply stay in uglyCommitBranch and do an interactive rebase: clean your commits there, and the force push that branch: your pull-request (if it existed before the rebase, a PR made from that branch) will update itself.
If there was no pull request yet, you still can push --force as long as nobody else was working on uglyCommitBranch (since it is your fork).


That being said, if you want to stay in newFeature branch, then:

git merge --squash uglyCommitBranch

(As described in "How to use git merge --squash?")


Or since March 2016, you can leave the "commit squashing" to the main repo maintainer.
See "Github squash commits from web interface on pull request after review comments?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250