Rebasing replays changes from one line of work onto another in the order they were introduced, whereas merging takes the endpoints and merges them together.
- Create a feature branch
$ git checkout -b feature
- Make changes on the feature branch
$ echo "Bam!" >>foo.md
$ git add foo.md
$ git commit -m 'Added awesome comment'
- Fetch upstream repository
$ git fetch upstream
- Rebase changes from feature branch onto upstream/master
$ git rebase upstream/master
5.Rebase local master onto feature branch
$ git checkout master
$ git rebase feature
- Push local master to upstream
$ git push upstream master
Rebasing gives you a clean linear commit history and creates non-obvious benefits to your project if used diligently. Think of it as taking a line of work and pretending it always started at the very latest revision.