Welcome to the Git and GitHub Lunch and Learn Exercise Repository! This repository serves as a hands-on learning platform for attendees of our Git and GitHub session. Here, you'll practice essential Git operations like forking, cloning, branching, committing, and creating pull requests. The primary goal is to familiarize you with the Git workflow in a collaborative setting. As part of the exercise, you'll be adding your name to this README file under the "Completed By:" section, along with a sentence about what you found most valuable in this exercise. Happy learning, and feel free to reach out if you have any questions!
- Savannah Burke
- Eric Rippetoe (Learning about forks and branches was new and useful to me)
In this live exercise, you'll practice a basic Git flow by forking a repository, cloning it, creating a new branch, making a change, committing that change, pushing the commit, and finally making a Pull Request (PR) into the main repo.
Forking creates a copy of the repository in your GitHub account, allowing you to make changes without affecting the original project.
- Navigate to the main repository on GitHub.
- Click the "Fork" button at the top-right corner.
Cloning downloads the repository to your local machine, enabling you to work on the project.
- Open GitHub Desktop.
- Click "File" -> "Clone repository."
- Choose the forked repository and select a local path.
- Click "Clone."
Branches allow you to work on features or fixes without affecting the main codebase.
- In GitHub Desktop, click "Current Branch" at the top.
- Click "New Branch" and give it a meaningful name.
- Click "Create Branch."
You'll be adding your name to a README file to practice making changes to a file.
- Navigate to the local repository folder.
- Open the README file.
- Under the title "Completed By:", add a bullet point with your name and a sentence on what you found most valuable in this exercise.
- Save the file.
Staging allows you to prepare and review changes before committing them.
- Return to GitHub Desktop.
- You'll see the changes in the "Changes" tab.
- Check the box next to the README file to stage the changes.
- Review the changes to ensure they are correct.
Note: Staging changes prepares them for commit but doesn't save them. Committing will save these changes.
Committing saves your changes locally with a record of what was changed and why.
- In GitHub Desktop, write a meaningful commit message describing your changes.
- Click "Commit to [your-branch-name]."
Pushing uploads your local commits to the remote repository on GitHub.
- In GitHub Desktop, click "Push origin" to push your commits to the remote repository.
A Pull Request proposes your changes to the original repository for review.
- Navigate to the original repository on GitHub.
- Click "Pull Requests" -> "New Pull Request."
- Choose your fork and branch as the source.
- Write a sensible title and description for your PR.
- Click "Create Pull Request."
Note: Make sure you're making the PR into the repo you forked from, not your own fork.
โน๏ธ Show Hint: Detailed Instructions: Making the PR into the Repo You Forked From, Not Your Own Fork
When you create a Pull Request (PR), the default behavior might be to propose changes to your own forked repository. However, the goal here is to propose changes to the original repository from which you forked. This is crucial for your changes to be reviewed and potentially merged into the main codebase.
- After pushing your changes, go to GitHub and navigate to your own fork of the repository.
- Click on the "Pull Requests" tab located near the top of the page.
- Click the green "New Pull Request" button. This will take you to a new page to configure the PR.
-
You'll see two dropdown menus at the top that specify the "base repository" and the "head repository."
- "Base repository" is where you want your changes to go.
- "Head repository" is where your changes are coming from.
-
By default, both the "base" and "head" repositories might be set to your own fork. You'll need to change the "base repository" to the original repository you forked from.
- Click on the "base repository" dropdown and select the original repository (not your fork).
- Ensure the "base" branch is set to
main
or the branch you want to merge your changes into. - The "head repository" should be your own fork, and the "compare" branch should be the branch where you made your changes.
- After setting the repositories and branches correctly, review the changes one more time to make sure everything looks good.
- Write a sensible title and a detailed description explaining what changes you've made and why.
- Click "Create Pull Request."
Note: Always double-check to ensure you're making the PR into the original repository you forked from, and not back into your own fork. This is crucial for your changes to be reviewed and considered for merging into the main project.
By following these steps, you'll ensure that your Pull Request is directed at the original repository, making it possible for your changes to be reviewed and potentially merged by the project maintainers.
Merging incorporates your changes into the main repository.
- Wait for your PR to be approved.
- Once your PR is approved, click "Merge Pull Request" on GitHub.
- Confirm the merge.
Congratulations, you've successfully completed the exercise! Your name should now appear in the README file of the main repository, signifying your completion of this hands-on Git exercise.