Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chose Greek God #5

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
76 changes: 34 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Git Tutorial: Handling Merges, Rebases, and Pull Requests
## Git Tutorial: Handling Merges and Pull Requests

### Prerequisites:

Expand All @@ -11,35 +11,44 @@ By the end of this tutorial, you should be able to:

1. Clone a repository.
2. Make changes and push them.
3. Resolve merge conflicts.
4. Use the rebase command.
5. Raise a pull request (PR).
3. Raise a pull request (PR).
4. Resolve merge conflicts.

### Let's Get Started!

#### 1. Clone the Repository:
#### 1. Fork the Repository:

Start by cloning the existing repository. This repository is located on a remote server, which is typically GitHub for most projects. By cloning it, you create a local copy on your machine which you can edit and push back to the remote repository.
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

```bash
$ git clone https://github.com/Waseem0912-coder/Introduction_to_Git
$ 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`

```bash
$ git branch -a
```

#### 2. Create a New Branch:

To avoid conflicts with the main codebase, always work on a new branch.
Checkout out the remote `dev` branch and then create a new branch from dev using the following command

```bash
$ git checkout remotes/origin/dev
$ git checkout -b [your_name]-choice
```

Replace `[your_name]` with your actual name.

#### 3. Choose Your Greek God:

Open the provided text file in the repository. Choose one Greek god from the following list and add it to the file:
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:

- Zeus
- Hera
- Poseidon
- Demeter
Expand All @@ -64,24 +73,21 @@ $ git commit -m "Chose my Greek god"
$ git push origin [your_name]-choice
```

#### 5. Rebase:
#### 5. Raise a Pull Request:

Before raising a PR, ensure your branch has the latest changes from the main branch of the remote repository. Rebasing allows you to apply your changes on top of the latest changes in the main branch.
Now, return to the GitHub repository online:

```bash
$ git checkout main
$ git pull origin main
$ git checkout [your_name]-choice
$ git rebase main
```
1. Click on "Pull Requests".
2. Select "New Pull Request".
3. For the base branch, choose "main" **from your Fork**. For the compare branch, pick your branch (`[your_name]-choice`) **from your Fork**.
4. Review your changes and click "Create Pull Request".
5. Add a title and description for your PR and submit.

If you encounter conflicts during the rebase (which is expected given the Greek god choice), proceed to step 6. If not, move on to step 7.
If you encounter conflicts during the PR (which is expected given the Greek god choice), proceed to step 6.

#### 6. Resolve Merge Conflicts:

Multiple students might have chosen the same Greek god, leading to a merge conflict.

Open the text file, and you'll see conflict markers:
Open the text file on GitHub by selecting the option to `Resolve Conflicts`, and on the web editor you'll see conflict markers:

```
<<<<<<< HEAD
Expand All @@ -93,29 +99,15 @@ Athena

To resolve this:

1. Decide which choice to keep or combine them.
1. Decide which choice to keep or combine them (in this case, keep your changes).
2. Remove the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`).
3. Save the file.

After resolving all conflicts:

```bash
$ git add .
$ git rebase --continue
```

If more conflicts arise, resolve them. Once there are no more conflicts, the rebase will conclude.

#### 7. Raise a Pull Request:
After resolving all conflicts, create the PR

Now, return to the GitHub repository online:

1. Click on "Pull Requests".
2. Select "New Pull Request".
3. For the base branch, choose "main". For the compare branch, pick your branch (`[your_name]-choice`).
4. Review your changes and click "Create Pull Request".
5. Add a title and description for your PR and submit.
#### 6. Merge 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.
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.
1 change: 1 addition & 0 deletions greek_gods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hera