When you have a long-running branch, you want to sync up with master
sometimes. You can do this by merging master
back into your branch, but Git has a better way of doing this. It's called rebasing. With rebasing, you can replay the commits from the branch over which you want to merge your changes. All this happens without a new commit being created and helps keep your history clean.
To see rebasing in action, we need to have a new branch with some commits and one commit in the master
branch. Let's do that first:
Go to the
super-git
project in your terminal and create a new branch:$ git checkout -b rebase-branch
Create a new file and commit it:
$ echo "File content" >> another_file.md $ git add . $ git commit -m 'Another commit'
Now, switch back to the
master
branch:$ git checkout master
Create a commit in the
master
branch:$ echo "1" >> README.md $ git add . $ git commit -m 'Commit in master'
We also want to have the commit that we...