Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pulling sometimes make me create a commit?

Tags:

git

I'm working with someone on the same branch.

I'm pulling each time after I've made changes to my working directory before I add or commit or push and only sometimes I get the below message. When does it do this and why?

Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch.

Lines starting with '#' will be ignored, and an empty message aborts the commit.

like image 838
akantoword Avatar asked Jun 13 '16 18:06

akantoword


People also ask

Does git pull create a new commit?

In the first stage of operation git pull will execute a git fetch scoped to the local branch that HEAD is pointed at. Once the content is downloaded, git pull will enter a merge workflow. A new merge commit will be-created and HEAD updated to point at the new commit.

Do you need to commit before pulling?

If you have uncommitted changes, the merge part of the git pull command will fail and your local branch will be untouched. Thus, you should always commit your changes in a branch before pulling new commits from a remote repository.

Does git pull always create a merge commit?

By default, the git pull command performs a merge, but you can force it to integrate the remote branch with a rebase by passing it the --rebase option.

What is the difference between pull and commit?

A commit is a discrete change to one or more files. It is a critical part of Git. A pull request is a request to merge one or more commits into a different branch. It is not part of Git; it is only part of GitHub (and similar services like BitBucket).


2 Answers

Simple answer: git pull is, essentially, a combination of git fetch and then a git merge.

As any merge, if Git finds out fast-forwarding is not possible, a traditional merge is necessary (one more commit with two parents), therefore this process asks for a commit message.

Reference: Git docs for branching and merging

like image 159
everton Avatar answered Sep 23 '22 13:09

everton


Please use git pull --rebase.

like image 28
Gaurav Agarwal Avatar answered Sep 23 '22 13:09

Gaurav Agarwal