Git merge only the final result of a development branch

If a Git repository structure looks like this:

master: A-C
dev:     \B-D-E

is it possible to merge the development branch into master so that only one commit is added to master, containing all of the changes found in all of the commits in the development branch. So the above structure would merge to look like this:

  • Does git remove files from version control after they are added to .gitignore?
  • Portable Git and GitHub: SSH Keys
  • Git cvsimport - No CVS folders which causes cvsexportcommit to fail
  • Maintaining and synchronizing a mirror remote Git repository
  • Who has my short lived feature branch?
  • Remove old commit information from a git repository to save space
  • master: A-C-E'

    The E' commit would contain all of the changes from the development branch and only the latest commit message, adding the new feature to master in one tidy commit.

    Is this possible in Git? I’m hoping to be able to keep the history of a GitHub repository tidy, as my development branches often contain early commits which are unfinished, unpolished and unfit for human consumption.

  • How does Perforce ignore file syntax differ from gitignore syntax?
  • Check out Project from Version Control Fails
  • How to Git fetch a remote repository and anchor it to a specified commit?
  • Is there a way to move a svn repository if you don't have access to the svn server?
  • OS X 10.10: Errors in locating and using brew and Git
  • git pull: update repo without changing the contents of a specific directory
  • 2 Solutions collect form web for “Git merge only the final result of a development branch”

    The merge part should be easy (see “How to use git-merge --squash?”):

    git checkout master
    git merge --squash dev

    You might have to adjust the commit message though:

    git commit --amend -m "<commit message from E>"

    (you have other options when doing the merge)

    You can achieve this, though it won’t be a merge. (Remember: A merge commit has 2 or more parents. E' only has one parent, though: C.)

    git rebase -i master dev
    • A text editor will open. Change pick to squash for all but the
      first line, then save the file and close the editor.
    • A text editor will open. (Populated with different content.) Edit its content to be the commit message you want for E', then save the file and close the editor.


    git checkout master
    git merge dev --ff-only
    git branch -d dev
    Git Baby is a git and github fan, let's start git clone.