top of page

GIT - Day-5

### Scenario 1: Practicing Pull Requests


#### Overview

In this scenario, you'll work on a shared repository and create a pull request to merge your changes into the main branch. This is a common workflow in collaborative projects.


#### Step-by-Step Instructions


1. Create a GitHub Repository:

- Go to GitHub and create a new repository named `pull-request-demo`.

- Initialize the repository with a README file.


2. Clone the Repository Locally:

- Open your terminal and clone the repository:

git clone https://github.com/your-username/pull-request-demo.git

- Navigate into the cloned repository:

cd pull-request-demo

3. Create a New Branch:

- Create a new branch for your feature or bug fix:

git checkout -b new-feature

4. Make Changes in the New Branch:

- Edit the README file or create a new file named `feature.txt` with some content:

echo "This is a new feature." > feature.txt

- Stage and commit your changes:

git add feature.txt

git commit -m "Add new feature"

5. Push the New Branch to GitHub:

- Push your new branch to the remote repository:

git push origin new-feature

6. Create a Pull Request on GitHub:

- Go to the `pull-request-demo` repository on GitHub.

- You'll see an option to compare & pull request for your recently pushed branch. Click on "Compare & pull request."

- Add a title and description for your pull request, then click "Create pull request."


7. Review and Merge the Pull Request:

- After creating the pull request, you or another collaborator can review the changes.

- If everything looks good, click "Merge pull request" to merge the changes into the main branch.


8. Delete the Feature Branch (Optional):

- Once the pull request is merged, you can delete the feature branch:

git branch -d new-feature

- On GitHub, you can also delete the remote branch from the pull request page.


 


### Scenario 2: Practicing Forks


#### Overview

In this scenario, you'll fork a public repository, make changes in your fork, and then create a pull request to suggest your changes to the original repository.


1. Fork a Public Repository on GitHub:

- Find a public repository you want to contribute to (you can use any public repository for practice).

- On the repository's GitHub page, click the "Fork" button at the top-right corner to create a fork under your GitHub account.


2. Clone Your Fork Locally:

- Clone the forked repository to your local machine:

git clone https://github.com/your-username/fork-demo.git

- Navigate into the cloned repository:

cd fork-demo

3. Set the Original Repository as an Upstream Remote:

- Add the original repository as an upstream remote to keep your fork updated:

git remote add upstream https://github.com/original-username/original-repository.git

- Verify the remotes:

git remote -v

4. Sync Your Fork with the Upstream Repository:

- Fetch the latest changes from the upstream repository:

git fetch upstream

- Merge the changes into your local main branch:

git checkout main

git merge upstream/main

5. Create a New Branch for Your Changes:

- Create a new branch for your changes:

git checkout -b my-contribution

6. Make and Commit Your Changes:

- Make your desired changes in the repository.

- Stage and commit your changes:

git add .

git commit -m "Fix issue or add a feature"

7. Push Your Branch to Your Fork:

- Push your branch to your fork on GitHub:

git push origin my-contribution

8. Create a Pull Request to the Original Repository:

- Go to your fork on GitHub.

- You'll see an option to "Compare & pull request" for your recently pushed branch. Click on "Compare & pull request."

- Ensure the base repository is the original repository and the base branch is `main or master`.

- Add a title and description, then click "Create pull request."


9. Review and Discuss the Pull Request:

- Collaborators of the original repository will review your pull request.

- You may receive feedback and requests for changes. You can make further commits to the same branch to address these requests.

- Once approved, your changes may be merged into the original repository.



These scenarios will help you practice and understand the workflows for creating pull requests and working with forks in GitHub.

DevOps Course New Batch | 6th April 2025 | 6:00  to 7:30 AM IST Price : 22000/-Rs | Duration : 2 Months

bottom of page