rico
rico

Reputation: 1935

Updating local git branch before pushing

I am working with my team on a project on bitbucket with git.

  1. I first clone the repo. => git clone
  2. I want to add a new file. => git add
  3. I commit my new file => git commit
  4. If I do a git status, I see my branch is one commit ahead.
  5. Some members of my team have also made changes, but no link with my new file added. I update my project before submitting => git pull origin master => this automatically triggers a merge(?!)
  6. If I do a git status, I see now my branch is ahead by 2 commits.
  7. I push my changes => git push origin master => my 2 commits are pushed

What I don't understand is why the git pull triggered a merge? There was no need here.

All I wanted was to commit a new file, why do I have finally 2 commits?

Thanks in advance.

Upvotes: 0

Views: 2520

Answers (1)

Alex Gitelman
Alex Gitelman

Reputation: 24722

The reason is that you and your coworkers made changes of the same base. So they need to be merged. You could eliminate extra commit if you do rebase instead of merge. Rebase would have effect like if you would get your coworkers changes before your change and then applied yours.

Upvotes: 1

Related Questions