- Fork and clone this repo.
- Create a branch from master named merge-main and rebase-main.
git branch merge-main
git branch rebase-main
- Push the new branches into the remote repo.
git checkout merge-main
git push -u origin merge-main
git checkout rebase-main
git push -u origin rebase-main
Before we get started, check out the current history of commits.
git log --graph --oneline
This is the ideal history we want to achieve.
NOTE: If you do not know the commands you need, I created a little git command cheat sheet at the bottom. Good luck!
- Go into your merge-main branch.
- Create a new branch named merge-feature-1.
- Create some commits on your merge-feature-1 branch.
- Push your merge-feature-1 branch into your remote repo.
- Create a pull request to merge the merge-main and merge-feature-1 branch.
You can learn how to create a pull request from here
- Review and merge your changes.
- Pull the changes on merge-main.
- Check out your commit history.
- Go into your merge-main branch.
- This time create two new branches: merge-feature-2 and merge-feature-3.
- Create some commits on your merge-feature-2 branch.
- Push your merge-feature-2 branch into your remote repo.
- Create a pull request to merge the merge-main and merge-feature-2 branch.
- Review and merge your changes.
- Pull the changes on merge-main.
- Check out the commit history of your merge-main branch.
- Go back into your merge-main branch.
- Create a new branch named merge-feature-4.
- Create some commits on your merge-feature-3 and merge-feature-4 branch.
- Push your merge-feature-3 and merge-feature-4 branch into your remote repo.
- Create a pull request to merge the merge-main and merge-feature-3 and merge-feature-4 branch.
- Review and merge your changes.
- Pull the changes on merge-main.
- Check out the commit history of your merge-main branch.
Do you notice the difference in the commit history when you're working with a single branch at a time and working with multiple branch at the same time?
How do we keep an organize history while working with multiple branches? The answer is we rebase!
We're going to follow similar steps that we took during activity two except we will rebase our branch before merging it into our main branch
- Go into your rebase-main branch.
- This time create two new branches: rebase-feature-1 and rebase-feature-2.
- Create some commits on your rebase-feature-1 branch.
Your branch is currently based on the most recent commit of master so rebasing will not do anything.
- Push your rebase-feature-1 branch into your remote repo.
- Create a pull request to merge the rebase-main and rebase-feature-1 branch.
- Review and merge your changes.
- Pull the changes on rebase-main.
- Check out the commit history of your rebase-main branch.
So far everything should look very similar to activity 2, but that is about to change.
- Go back into your rebase-main branch.
- Create a new branch named rebase-feature-3.
- Create some commits on your rebase-feature-2 and rebase-feature-3 branch.
- Rebase your rebase-feature-2 branch onto rebase-main.
- Push your rebase-feature-2 branch into your remote repo.
- Create a pull request to merge the rebase-main and rebase-feature-2.
- Review and merge your changes.
- Pull the changes on rebase-main.
- Before we rebase rebase-feature-3, check out the commit history of rebase-feature-3.
- Rebase your rebase-feature-3 branch onto master.
Check the commit history or rebase-feature-3, does it look different?
- Push your rebase-feature-3 branch into your remote repo.
- Create a pull request to merge the rebase-main and rebase-feature-3.
- Review and merge your changes.
- Pull the changes on rebase-main.
- Check out the commit history of your rebase-main branch.
Compare the history of commits on merge-main vs. rebase-main, what do you notice?
Command | Results |
---|---|
git branch [branch name] |
Creates a new branch. |
git checkout [branch name] |
Switches to the branch. |
git checkout -b [branch name] |
Creates a new branch and switches to it. |
git add . |
Adds all changes in the repo to the staging area. |
git commit -m [log message] |
Commits all the changes in the staging area. |
git pull [branch name] |
Updates your local repo based on your remote repo. |
git push -u origin [branch name] |
Pushes your local branch for the first time into the remote repo. |
git rebase master [branch name] |
Moves the starting point of your branch to the most recent commit on master. |
git log --graph --oneline |
Visually displays your commit history |