Csaba Molnár
Csaba Molnár

Reputation: 17

Push master without feature branches

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

Upvotes: 1

Views: 421

Answers (2)

Chris Maes
Chris Maes

Reputation: 37752

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

Upvotes: 1

Thong Kuah
Thong Kuah

Reputation: 3283

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.

Upvotes: 0

Related Questions