Exercises - Working with remotes¶
In order to do these exercises, you need to download the exercises zip file (if you already did so for the previous exercise, you do not need to do so again, of course).
You can do that either by cloning the repository or by just getting the zip file with wget.
- Do ONE of the following:
- git clone
git clone https://github.com/hpc2n/course-intro-git.gitcd course-intro-gitunzip git_materials.zipcd git_materialscd 6.remotes
- Fetch with wget
wget https://github.com/hpc2n/course-intro-git/raw/refs/heads/main/git_materials.zipunzip git_materials.zipcd git_materialscd 6.remotes
- git clone
You are now in a directory with 2 subdirectories, one for each exercise.
Adding remotes¶
Make sure you are in the subdirectory git_materials/6.remotes/1.adding-remotes.
- Fork the following repository
https://github.com/pojeda/pull-request-course.git - Clone the forked repository and check the available remotes
- Add the upstream repository with the name “upstream”
- Using your cloned version of the forked repository, make some modification to the “README.md” file and commit them locally. Then, push the changes to the remote.
Finally, make a “pull request” from your GitHub account.
Merge conflicts and rebasing¶
Make sure you are in the subdirectory git_materials/6.remotes/2.merge-rebase.
Note
This exercise demonstrates how to solve a merge conflict using rebasing.
Note: for the present example you don’t need to add a remote. It has been added for this example already.
Tasks:
- Enter the
repositorydirectory and check the current status. - Check that the file
file.txthas been modified since the last commit using the diff command - Try commiting the changes and push them to the remote
- Why do the push was unsuccesful?
hint: the remote contains changes that are missing from your local remote. - Pull the changes from the remote
- When the text editor opens save the commit message. This means that
Git is able to merge the remote and your local changes.
- Take a look at the commits’ tree graph:
and save it into a text file for further investigations. - You could simply continue to work normally from here but the merge commit you just created is not actually necessary in this situation. Try falling back to the previous commit:
- Now, pull again but tell Git to rebase your branch:
- Take a look at the graph once again with:
and compare it with the one you saved into a text file. You can now see that the merge commit was not necessary. - Finally, you can now push the changes to the remote.