1

I've done quite a lot of search on this problem but didn't find an answer, though it seems to be a common scenario. Sorry if it is still a duplicate.

I use Git to manage my Java source files. I'm the only developer. I created a 'remote' repository on a LAN share. I regularly 'push' my master branch to this remote repository, because the LAN share is safe against data loss (it is backed up). I use TortoiseGit on Windows, I do not use Git command-line.

Usually, I work on 2-3 new features in parallel. I create a new Git branch for each feature (aka feature branches). When I'm done with a feature, I merge it to master by creating a 'merge commit'. This works fine.

After merging I 'push' my master branch to the remote repository so that my changes are safe. My problem is that this does not do exactly what I want. My 'merge commit' is pushed to the remote without problems. However, all commits in my feature branch are also pushed. I do not want this. In my remote repository I only want to see a 'clean' master branch. My feature branch contains all kinds of intermediate commits. Obviously these are not needed and confusing in my remote repository.

I use TortoiseGit 1.8.15.0. When I 'push' my changes, the 'Ref' section of the popup window shows Local=master, Remote=master. Also, 'Push all branches' is not checked (default). In the bottom section of the window everything is at the default, which means that only 'Autoload Putty Key' is checked.

What am I doing wrong and how could I achieve a 'clean' master branch on my remote?

Additional info: my branch structure looks like the one on the git-merge man page

          A---B---C feature1
         /         \
        D---E---F---G---H master
Chris Maes
  • 26,426
  • 4
  • 84
  • 113

2 Answers2

1

Most people wish to see how each feature was developed and thus wish to keep all those commits. If you don't, consider using the --squash option:

git merge --squash feature-branch

which will put all developments from the feature branch in one commit like this:

D---E---F---G*---H master

with G* being one single commit containing all changes introduced in the commits A, B, C.

You can see this visually on this page

Chris Maes
  • 26,426
  • 4
  • 84
  • 113
  • I tested your suggestion and it does exactly what I want. Actually, after @Thong mentioned 'squash' I found http://stackoverflow.com/questions/5308816/how-to-use-git-merge-squash which also gives the above solution and some alternatives. Thanks to both of you. (@Thong I upvoted your answer but I don't have 15 reputation, yet.) – Csaba Molnár Jan 11 '16 at 14:37
0

Usually, I work on 2-3 new features in parallel. I create a new Git branch for each feature (aka feature branches). When I'm done with a feature, I merge it to master by creating a 'merge commit'. This works fine.

Presumably you are only seeing commits from a feature branch you have merged into master. This is the very point of merging branches in git - you essentially bring in the commits from your feature branch into the master branch, aka "merge".

I think you are looking to achieve some notion of cleaning up your commits in your feature branch ? Why ? There is no real need to make commits tidy if you are developing solo. There's options to perform a squash merge and/or rebase your feature branch to tidy it up, but I suggest you get comfortable with the basics of git first.

Thong Kuah
  • 3,063
  • 1
  • 16
  • 28
  • I want to keep a 'clean' remote with a single master branch which doesn't contain my intermediate commits (1 at the end of each day, for example) is because this Java project might later be handed over to another solo developer who needn't/shouldn't see my intermediate commits. After reading the first few paragraphs of https://git-scm.com/docs/git-merge my idea was that only the last state of my feature branch (C) will be merged into master as a new commit (H). This should not include commits A and B. What am I missing here? – Csaba Molnár Jan 11 '16 at 14:00