Exercise: use a remote repository¶
In this exercise, you will use a remote repository to synchronise and merge changes between multiple local repositories, starting from the local git-exercise
repository that you created in the previous exercise.
Create a remote repository¶
-
Create a new remote repository on a platform such as GitHub. You can make this a private repository, because you won't need to share it with anyone.
-
Link your local
git-exercise
repository to this remote repository, and push all branches and tags to this remote repository.
Clone the remote repository¶
-
Make a local copy of this remote repository called
git-exercise-2
. -
Check out the
main
ormaster
branch. The files should be identical to themilestone-2
tag in your originalgit-exercise
repository.
Work on the new local repository¶
-
Create a new branch called
feature/report
. Check out this branch and create a new file calledreport.md
. Edit this file so that it contains: -
A brief description of the generated data set;
- A table of the summary statistics printed by the plotting scripting (see the Markdown Guide); and
- The figure produced by the plotting script (see the Markdown Guide).
Record your changes in a new commit.
- Push this new branch to the remote repository.
Merge the report into the original repository¶
-
In your original
git-exercise
repository, checkout thefeature/report
branch from the remote repository and verify that it now contains the filereport.md
. -
Merge this branch into your
main
ormaster
branch, and add a new tagmilestone-3-report
. -
Push the updated
main
ormaster
branch to the remote repository.
Update the new local repository¶
- In your
git-exercise-2
repository, checkout themain
ormaster
branch and pull changes from the remote repository. It should now contain the filereport.md
.
Info
Congratulations! You have used a remote repository to synchronise and merge changes between two local repositories. You can use this workflow to collaborate with colleagues.
Self evaluation¶
Now that you have used commits and branches to share work between multiple repositories, here are some questions for you to consider:
-
Do you feel comfortable in deciding which changes to record in a single commit?
-
Do you feel that your commit messages help describe the changes that you have made in this repository?
-
Do you feel comfortable in using multiple branches to work on separate ideas in parallel?
-
Do you have any current projects that you might want to work on using local and remote
git
repositories?