- Basic knowledge of Git commands.
- A GitHub account.
By the end of this tutorial, you should be able to:
- Clone a repository.
- Make changes and push them.
- Raise a pull request (PR).
- Resolve merge conflicts.
Start by forking the existing repository. This repository is located on a remote server, which is typically GitHub for most projects. By forking it, you create a local copy which you can edit and push back to the remote repository.
When you fork the project, make sure to unselect the option to Copy the main branch only
Next clone the repo
$ git clone https://github.com/[YOUR_GITHUB_ID]/Introduction_to_Git/
If you check the repo, you should see the two branches main
and dev
$ git branch -a
Checkout out the remote dev
branch and then create a new branch from dev using the following command
$ git checkout remotes/origin/dev
$ git checkout -b [your_name]-choice
Replace [your_name]
with your actual name.
Open the provided text file greek_gods.tx
in the repository. Choose one Greek god from the following list and replace the one in the file:
- Hera
- Poseidon
- Demeter
- Athena
- Apollo
- Artemis
- Ares
- Aphrodite
- Hephaestus
- Hermes
- Dionysus
Save and close the file.
Commit your changes and push them to your branch on the remote GitHub repository.
$ git add .
$ git commit -m "Chose my Greek god"
$ git push origin [your_name]-choice
Now, return to the GitHub repository online:
- Click on "Pull Requests".
- Select "New Pull Request".
- For the base branch, choose "main" from your Fork. For the compare branch, pick your branch (
[your_name]-choice
) from your Fork. - Review your changes and click "Create Pull Request".
- Add a title and description for your PR and submit.
If you encounter conflicts during the PR (which is expected given the Greek god choice), proceed to step 6.
Open the text file on GitHub by selecting the option to Resolve Conflicts
, and on the web editor you'll see conflict markers:
<<<<<<< HEAD
Apollo
=======
Athena
>>>>>>> [commit_hash]
To resolve this:
- Decide which choice to keep or combine them (in this case, keep your changes).
- Remove the conflict markers (
<<<<<<<
,=======
,>>>>>>>
). - Save the file.
After resolving all conflicts, create the PR
Finally, merge the PR.
Congratulations! You've now tackled changes, navigated conflicts, and initiated a PR. Handling merge conflicts can seem daunting at first, but with practice, it becomes intuitive. This exercise imparts the collaborative flow of team projects using Git and GitHub, enhancing your version control skills.