Kimkorng

Real Project Development with Git and GitHub

03 FEB, 2025

Git and GitHub are like the dream team for working on code together. Git tracks all the changes you make to your code, and GitHub is where you store and share it with your team. Let's dive in and see how to make the most of them!😎


🚀 Create a Repo on GitHub

Let’s start by setting up a spot for your project!

  1. Head over to GitHub and click on New Repository.
  2. Name your repo and add a .gitignore file (choose one for Python, Node.js, etc. to skip unnecessary files).
  3. Don’t forget a README.md file to explain what your project is about.

🦾Make sure you have registered a GitHub account.

📂 Clone the Repo to Your Computer

Everyone needs a copy of the project on their computer. Here’s how to get it:

shell
git clone https://github.com/your-username/your-repo.git

🌿 Branching for Better Organization

Good branches = smooth teamwork! One cool way to manage branches is using Git Flow.

🌳 Main Branches

  • main or master: The “stable” version of your project. Only tested and ready-to-ship code should go here.
  • develop: The place where all new changes hang out before getting added to main.

✨ Feature Branches

For each new feature or task, create its own branch:

shell
git checkout -b feature/your-feature-name

Then, push it up to GitHub:

shell
git push origin feature/your-feature-name

🔥 Hotfix Branches

If there’s an urgent bug, create a hotfix branch directly from main:

shell
git checkout -b hotfix/your-hotfix-name

📤 Push and Pull Code Like a Pro

You’ll want to keep your code updated. Here’s how to push your work and pull in the latest changes.

Push Your Changes

Once you’ve made some updates:

shell
git add . git commit -m "your awesome commit message" git push origin your-branch-name

Pull the Latest Code

Before jumping in, grab the latest updates:

shell
git pull origin develop

⚔️ Merge Conflicts? No Problem!

Sometimes, two people might change the same part of a file and cause a merge conflict. Here’s how to fix it:

  1. Pull the latest changes:
    shell
    git pull origin develop
  2. Open the file and fix the conflict (Git will mark where the problem is).
  3. Add the fixed file:
    shell
    git add conflicting-file
  4. Commit the fix:
    shell
    git commit -m "fixed merge conflict"

🔄 Using Pull Requests (PRs) for Code Reviews

PRs are key for getting code reviewed and merged. Here’s how to create one:

  1. Push your feature branch to GitHub.
  2. Open GitHub and click New Pull Request.
  3. Set your branch as the source and develop as the target.
  4. Add a title and a short description.
  5. Ask your teammates to review it.

Review and Merge

Your teammates will check your code, leave feedback, and once everything looks good, they’ll merge it into develop.


📌 Manage Tasks with Issues and Project Boards

GitHub is great for organizing your work too!

Issues

  • Create issues for bugs or new features.
  • Assign them to team members and link them to PRs.

Project Boards

Use GitHub Projects to track tasks with boards like To Do, In Progress, and Done.


🔍 Code Review Tips

Code reviews make the project stronger!

If You’re Reviewing

  • Be clear and constructive with your feedback.
  • Check if the code works and is easy to understand.

If You’re the Developer

  • Address all the review comments.
  • Test your code before asking for feedback.

🤖 Automate with GitHub Actions

Want to run tests automatically? GitHub Actions is your friend. Here’s a simple example to get started:

Create a .github/workflows/ci.yml file:

yaml
name: CI on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Node.js uses: actions/setup-node@v2 with: node-version: '14' - run: npm install - run: npm test
SHARE
views