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!
- Head over to GitHub and click on New Repository.
- Name your repo and add a
.gitignore
file (choose one for Python, Node.js, etc. to skip unnecessary files). - 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:
shellgit 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
ormaster
: 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 tomain
.
✨ Feature Branches
For each new feature or task, create its own branch:
shellgit checkout -b feature/your-feature-name
Then, push it up to GitHub:
shellgit push origin feature/your-feature-name
🔥 Hotfix Branches
If there’s an urgent bug, create a hotfix branch directly from main
:
shellgit 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:
shellgit 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:
shellgit 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:
- Pull the latest changes:
shell
git pull origin develop
- Open the file and fix the conflict (Git will mark where the problem is).
- Add the fixed file:
shell
git add conflicting-file
- 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:
- Push your feature branch to GitHub.
- Open GitHub and click New Pull Request.
- Set your branch as the source and
develop
as the target. - Add a title and a short description.
- 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:
yamlname: 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