0

I'm a beginner with GIT and I'm trying to implement as followed : Ideal Workflow

To explain that, I want to implement each feature to have a it's own branch and when it is over and the feature is working how I want (here B.3) I simply want to clone the B.3 into a new main commit (which is C in the picture). Then B.3 = C

I believe that If I do a git merge, B1, B2 and B3 would be cloned into main. But I don't want the history of the feature in the main branch, I just want the last one in order to get a main branch clean which evolve feature after feature.

PS: Since I work alone in the dev projects, I don't need other specific branch or else. :)

Is it even possible? (I believe so after discovering the power of git !)

Thanks! :)

  • B.3 contains B.2 plus some modifications and B.2 contains B.1 plus some modifications right? – nissim abehcera Apr 04 '21 at 17:02
  • Yes exactly ! It is just the evolution and tests of the feature. B.3 is the final state – user15546658 Apr 04 '21 at 17:04
  • Does this answer your question? [Merge only the last commit from a branch into master](https://stackoverflow.com/questions/56039980/merge-only-the-last-commit-from-a-branch-into-master) – Asif Kamran Malick Apr 04 '21 at 17:07
  • Thanks for the link. I didn't know about cherry picking. I'm a bit confused now. What is the difference between cherry picking the last commit of a branch and merge the branch ? If I merge the branch, will I have 3 new commits in my main or just one ? I just want as less commit as possible in the main branch :/ – user15546658 Apr 04 '21 at 17:22
  • 1
    You've worded the question in a conflicting way IMO. To me it sounds like you want the *contents* of commit B.1, B.2, and B.3, from your branch to look as *one commit* on your main branch. You're looking for a [squash](https://www.git-tower.com/learn/git/faq/git-squash/). You take several commits and "replay" them into a single commit, with a commit message that generally describes the entirety of the squashed commit. You lose the "history" of how things evolved in the branch you squashed to, so it looks like a single commit. – Kritner Apr 04 '21 at 17:27
  • 1
    In short, merge carries forward everything, cherry-pick is what the name says , i.e. pick what you wish. Merge alone is something you don't want as per your current requirement. – Asif Kamran Malick Apr 04 '21 at 17:57
  • 2
    Since you have just started out on your git journey, I would like to point you to few very useful resources : [Atlassian-Git-Tutorial](https://www.atlassian.com/git/tutorials/what-is-git), [Learn Git Branching](https://learngitbranching.js.org/), [GitHub's Git Resources](https://try.github.io/). and lastly [this SO post](https://stackoverflow.com/a/53972713/2915738) which answers the merge vs cherry-pick, and [another one from same post](https://stackoverflow.com/a/53974633/2915738), but I believe this last post will be a bit heavy considering you have just started out learning git. – Asif Kamran Malick Apr 04 '21 at 18:05

1 Answers1

1

On a Github pull request you can use the Squash and Merge button

ryanve
  • 50,076
  • 30
  • 102
  • 137