6

What are the differences between git pull , git fetch and git rebase? I feel pull and fetch are same.

Lakmal Vithanage
  • 2,767
  • 7
  • 42
  • 58

1 Answers1

5

Fetch: update local with remote changes but not merge with any local branch.

Pull: update local and merge the changes with current-branch.

  • git fetch: Get the latest changes from origin (no merge)

  • git pull = git fetch + git merge

  • If you rebase feature branch onto master branch. git rebase master, it would keep the feature branch commits/changes top.

    Say you have two commits in master branch (A -> C) and two commits in feature branch (B -> D).

    Assume you are in feature branch (git checkout feature). Now if you merge master then commit history:

    (previous commit) - A -- C       <- master
                      \        \
                        B -- D -- M   <- feature
    

    Here, M for new-merge-commit-sha.

    For rebase master, commit history: (A -> C -> B' -> D').

Sajib Khan
  • 22,878
  • 9
  • 63
  • 73