Moving between branches
Now that you’ve made and recorded some changes on your working branch and synced them to the remote repo, we can look at how to move between branches and what that looks like in terms of file changes.
Switching branches is useful for when we might need to pause our work on one branch and continue working on an issue in another branch. Before you switch branches it is important to commit the changes you made in the branch you’re currently in. It’s also important to pull changes after you switch to your new branch.
Assuming you’ve not skipped any steps, you should now have at least 2 branches that you’ve had created during this tutorial: <github_username>/main
and <github_username>/development
, as well as the original main
, branch.
Use git checkout
to switch between these branches.
git checkout main
git checkout <github_username>/main
git checkout <github_username>/development
replacing <github_username>
with your own username.
Check the contents of the git-academy-log.md file each time you switch branches and you should see changes occur everytime you switch.
You can also use the git switch
command interchangeably with the git checkout command for switching branches.
Go to the right hand side of RStudio and click on the Git tab.
Click on the downwards arrow to “pull” the latest changes from the remote repo. This ensures that:
- you have a full list of remote branches.
- you have the latest changes in the code to avoid conflicts.
Click on the drop down menu of branches.
Click on
main
Check the “git-academy-log.md” file and you’ll see your edits have disappeared.
Click on the drop down menu of branches.
Click on
<github_username>/main
- Check the “git-academy-log.md” file and you’ll see your edits have returned.
Click on the branches drop down menu at the top of the screen.
Click the Fetch icon to “pull” the latest changes from the remote repo. This ensures that:
- you have a full list of remote branches.
- you have the latest changes in the code to avoid conflicts.
Click on “Remote” to see the full list of remote branches if you can’t already.
Click on
main
and then click “Checkout”.
- Check the “git-academy-log.md” file and you’ll see your edits have disappeared.
Click on the branches drop down menu at the top of the screen.
Click on
<github_username>/main
and then click “Checkout”.Check the “git-academy-log.md” file and you’ll see your edits have returned.