2

I'm working on a project that uses GIT as version control system. In the project's development process, it says that

Do not use "git pull" since that will cause a merge and create a very messy history over time. Use git fetch and git rebase instead.

Basically I know git pull actually does git fetch + git merge. And git rebase will keep the commit graph clean, because after git rebase, the local branch becomes to be at same line as the remote branch.

But I still don't understand why git pull create a very messy history? Could anybody explain that to me?

1

2 Answers 2

3

Fetch + rebase will create linear history (each commit has ONLY ONE PARENT) like

last common commit <- remote commit <- remote commit <- local commit 

Pull, if there are some changes both in remote branch and in your local will create messy history (commit can have TWO PARENTS - look at "merge commit") like

 remote commit <- remote commit last common commit <- <- merge commit local commit 
Sign up to request clarification or add additional context in comments.

1 Comment

I'd like to point out that git pull has a --rebase(-r) option which causes it to rebase after fetching instead of merging.
1

You could check the official documentation between about git fetch + rebase and git pull here. But former is usually the better approach as compared to git pull. git pull fetches the current branch and immediately merges it. (Could be pretty nasty to fix it you get conflicts).

Where as rebase adjust the head of the current branch against the one it is being rebased. Thus you get a linear history.

So, always be rebasing when are working on a setup where more than one developers are contributing to a repository or branch.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.