Forking a Repository and Creating a Pull Request

Forking a Repository and Creating a Pull Request

Today, I want to share my experience of learning how to fork a repository, create a branch, and make a pull request. Initially, I tried doing this through the Coursera lab environment using Visual Studio Code, but I ran into some problems. So, I decided to switch to my personal setup on Git Bash. Here’s how it went down:

Starting with the Coursera Lab

I began with the Coursera lab, which provided a Visual Studio Code environment. The task was simple: fork a repository, make some changes, and then create a pull request. However, I quickly hit some roadblocks.

Issues Encountered

  1. File Not Found Errors: Even though I followed the instructions carefully, I kept getting “No such file or directory” errors when trying to clone and navigate the repository.
  2. Visual Studio Code Limitations: The Coursera lab environment seemed restricted, and I couldn’t perform some necessary operations smoothly.

After several attempts and facing the same issues repeatedly, I decided to switch gears and use my personal laptop with Git Bash. This turned out to be a great move.

Switching to Git Bash on My Laptop

Here’s what I did using Git Bash:

Step 1: Forking the Repository

First, I forked the repository on GitHub. I chose the octocat/Spoon-Knife repository for practice.

  1. Visit the Repository: I went to the GitHub page for octocat/Spoon-Knife.
  2. Fork the Repository: I clicked the "Fork" button at the top right of the page to create a personal copy of the repository in my GitHub account.

Step 2: Cloning the Forked Repository Locally

Next, I cloned the forked repository to my local machine.

  1. Open Git Bash: I opened Git Bash on my laptop.
  2. Clone the Repository: I used this command to clone the repository:

gh repo clone <my-username>/Spoon-Knife        

3. Navigate to the Repository: After cloning, I navigated into the directory:

cd Spoon-Knife        

Step 3: Creating and Checking Out a New Branch

To keep my changes organized, I created a new branch.

  1. Create a Branch: I created and checked out a new branch named my-branch:

git checkout -b my-branch        

Step 4: Making Changes

I then made some changes to the index.html file.

  1. Edit the File: I opened the index.html file using Nano:

nano index.html        

2. Add My Details: I added my name and the certification I am working on to the file.

Step 5: Adding and Committing Changes

With the changes made, I staged and committed them.

  1. Add the Changes: I added the modified file:

git add index.html        

2. Commit the Changes: I committed the changes with a message:

git commit -m "Added my name and certification to index.html"        

Step 6: Pushing Changes to GitHub

Next, I pushed my changes to the forked repository on GitHub.

  1. Push the Branch: I pushed the changes to the my-branch branch on GitHub:

git push origin my-branch        

Step 7: Creating a Pull Request

Finally, I created a pull request to merge my changes into the original repository.

  1. Open GitHub: I went back to the GitHub page for my forked repository.
  2. Create Pull Request: I navigated to the "Pull Requests" tab and clicked "New Pull Request."
  3. Compare Branches: I selected my branch (my-branch) to merge into the base repository’s main branch.
  4. Submit the Pull Request: I gave my pull request a title and description, then clicked "Create Pull Request."

Conclusion

This experience taught me a lot about version control and using GitHub effectively. Despite the initial problems with the Coursera lab environment, switching to my personal setup allowed me to complete the task successfully. Now, I have a better understanding of forking a repository, creating a branch, making changes, and submitting a pull request. This hands-on practice was really helpful, and I’m excited to use these skills in future projects.

要查看或添加评论,请登录

Arta F.的更多文章

社区洞察

其他会员也浏览了