1

I have a class of students in which we all work in a repository and constantly check in small status updates and code, etc.

We have noticed that in addition to our commits that we make, Git also seems to create merges and check these in as well, see screenshot.

These commits are full of changes from other team members and so are only confusing to us an clutter our git history.

What are these automatic commits and is there any way to configure Git not to make these commits?

enter image description here

Edward Tanguay
  • 183,467
  • 302
  • 701
  • 1,026
  • Sounds like you're merging with `no-ff`, or `merge.ff` is false in the config. It looks like you're using some kind of UI wrapper around git, so you'll need to check its documentation for merge configuration. – William Pursell Apr 02 '21 at 15:26
  • But nobody is merging branches at all. We're simply updating files in each of our directories, pushing them as commits to the dev branch at GitHub and pulling commits from the dev branch from GitHub. We only work in the dev branch and so aren't creating branches or merging them back. What could be creating these "Merge branch 'dev'' of nnn into dev" entries? – Edward Tanguay Apr 02 '21 at 15:31
  • Given that it is branches from github merging into dev, perhaps someone is doing `git pull --no-ff` or has `pull.ff` configured to false. – William Pursell Apr 02 '21 at 15:38

2 Answers2

6

Your comment explains why this is happening:

We're simply updating files in each of our directories, pushing them as commits to the dev branch at GitHub and pulling commits from the dev branch from GitHub.

It's the pull that causes the merge commits. Presumably you are all checking out the dev branch, making your commits, and at some point pulling the latest. When you pull commits from the remote version of your branch and you also have new commits on your local branch, the default setting in Git will create a merge commit.

To avoid it, you have a few options:

  1. When pulling, use git pull --rebase. This will rebase your local commits onto the latest version of dev instead of creating a merge commit. If this is the way you decide to go, you can have everyone configure this to happen automatically.
  2. Don't pull anymore. If you want to update your local copy of dev, first do git fetch followed by git rebase origin/dev. The outcome is the same as #1, but this makes it more obvious that you are doing it.
  3. Similar to #2, you could start using separate branches instead of everyone working on dev. Before you merge into dev, do a git fetch followed by git rebase origin/dev.

Number 3 is probably the best way to go, but is a slightly more complicated workflow. But it enables task switching if you want to work on different things at the same time.

TTT
  • 14,202
  • 7
  • 53
  • 56
1

Try using git pull -r to rebase your commits on top of the latest origin/master, instead of creating a merge commit. Although to create a proper workflow with your teammates you should use branches, this is a way to get rid of merge commits.

larsl
  • 329
  • 1
  • 9