Week 1, Lesson 3: Git, GitHub & Your First Fork
In the world of software development, we rarely work alone. We work on teams, and we need a way to collaborate on the same codebase without overwriting each other’s work. The tools that make this possible are Git and GitHub.
What is Git?
Git is a version control system. Think of it like the “track changes” feature in Google Docs, but for code. It’s a program that runs on your computer and keeps a full history of every change you make to your project. This allows you to:
- See who changed what, and when.
- Go back to a previous version of your code if you make a mistake.
- Work on a new feature without affecting the main codebase.
What is GitHub?
GitHub is a website and cloud-based service that helps developers store and manage their code using Git. It’s a place to host your Git repositories online. GitHub adds a social and collaboration layer on top of Git, allowing you to:
- Share your code with others.
- Work on projects with a team.
- Review code and discuss changes before they are merged into the main project.
Analogy: If Git is the tool for tracking changes, GitHub is the shared online library where all the books (repositories) with their change histories are stored.
The Core Workflow: Find an Issue, Fork, Clone, Branch, Commit, Push, PR
For this program, you won’t be working directly on the main project repository. Instead, you’ll be working on your own copy, and then proposing your changes back to the team’s project. This is a very common and safe way to work.
✅ Step 1: Find and Assign Your First Issue
Before you write any code, you need to know what to work on. All of your work is organized in your team’s GitHub Project board.
- Go to your team’s GitHub repository and click the “Projects” tab.
- Find an issue in the “To Do” column that you want to work on.
- Click on the issue to open it, and in the right-hand sidebar, assign it to yourself. This tells your team you’re working on it.
✅ Step 2: Fork the Repository
A fork is your own personal copy of a repository. You will receive a link to your team’s main repository on GitHub. Your first step is to fork it.
- Go to your team’s repository page on GitHub.
- In the top-right corner of the page, click the “Fork” button.
- This will create a new repository under your own GitHub account with the same name. This is your copy.
✅ Step 3: Clone Your Fork
Now that you have your own copy on GitHub, you need to get it onto your computer. This is called cloning.
- On your forked repository’s GitHub page, click the green “<> Code” button.
- Make sure you’re on the “HTTPS” tab, and copy the URL.
- Open your terminal in VS Code and run the
git clonecommand with the URL you just copied:
git clone https://github.com/YOUR-USERNAME/your-repo-name.git
- This will download the repository to your computer. Open this new folder in VS Code.
✅ Step 4: Create a New Branch
Before you start writing any code, you should create a new branch. A branch is like a separate timeline of your project. This allows you to work on a new feature without affecting the main
main branch. It’s a best practice to include the issue number in your branch name.In your terminal, run:
git checkout -b your-initials/issue-1-feature-name # Example: git checkout -b kd/issue-1-add-homepage-title
This creates a new branch and switches you to it. Now you’re ready to code!
Before you start writing any code, you should create a new branch. A branch is like a separate timeline of your project. This allows you to work on a new feature without affecting the main
main branch.In your terminal, run:
git checkout -b your-initials/feature-name # Example: git checkout -b kd/add-homepage-title
This creates a new branch and switches you to it. Now you’re ready to code!
✅ Step 5: Commit and Push Your Changes
As you work, you should save your changes to Git. This is a two-step process: commit and push.
- Commit: A commit is a snapshot of your code at a specific point in time. It’s a good practice to make small, frequent commits.
# Add all your changed files to the staging area git add . # Commit them with a descriptive message git commit -m "feat: add a title to the homepage"
- Push: Pushing sends your committed changes from your local computer up to your forked repository on GitHub.
git push -u origin your-branch-name
✅ Step 6: Open a Pull Request (PR)
A Pull Request (PR) is how you propose your changes to the team’s main repository. It’s a request to “pull” your changes from your branch into the
main branch of the team’s project.- Go to your team’s repository on GitHub.
- You should see a yellow banner that says “your-branch-name had recent pushes.” Click the “Compare & pull request” button.
- Give your PR a clear title and a description of the changes you made.
- In the description, link the issue your PR is for by typing “Closes #” and the issue number (e.g., “Closes #1”). This will automatically close the issue when your PR is merged.
- Click “Create pull request.”
A Pull Request (PR) is how you propose your changes to the team’s main repository. It’s a request to “pull” your changes from your branch into the
main branch of the team’s project.- Go to your team’s repository on GitHub.
- You should see a yellow banner that says “your-branch-name had recent pushes.” Click the “Compare & pull request” button.
- Give your PR a clear title and a description of the changes you made.
- Click “Create pull request.”
Your team can now review your code, leave comments, and once it’s approved, it can be merged into the main project!
This workflow might seem like a lot of steps at first, but it will quickly become second nature. It’s the standard way that software teams all over the world collaborate, and it’s a crucial skill for any developer.