๐Ÿค

Collaborate with Git

๐Ÿง‘โ€๐ŸŽ“ Apprenticeโฑ๏ธ 20 minutes

๐Ÿ“‹ Suggested prerequisites

  • โ€ขMy First Repository completed

What you'll build

You'll learn the complete Git collaboration workflow: clone repos, create branches, make commits, and open Pull Requests. You'll practice the team workflow by simulating contributions to a project, resolving conflicts, and merging. When you're done, you'll know how to work on any open source project or development team using the standard Git flow. It's the skill that allows you to contribute to real projects and work professionally with other developers.


Basic collaboration flow

  1. Clone the repo
  2. Create a branch
  3. Make changes
  4. Open a Pull Request
  5. Someone reviews
  6. Merge happens

Step 1: Clone a repository

git clone https://github.com/user/project.git
cd project

Step 2: Create a branch

git checkout -b my-feature

Now your changes are isolated.


Step 3: Make changes and commit

# Edit files...
git add .
git commit -m "Add new feature"

Step 4: Push the branch

git push -u origin my-feature

Step 5: Open Pull Request

  1. Go to GitHub
  2. You'll see a "Compare & pull request" button
  3. Describe your changes
  4. Assign reviewers

Branch commands

CommandWhat it does
git branchList branches
git checkout branchSwitch to branch
git checkout -b newCreate and switch
git merge branchMerge branch
git branch -d branchDelete branch

Resolve conflicts

When two people edit the same thing:

<<<<<<< HEAD
Your code
=======
Other's code
>>>>>>> other-branch
  1. Choose which code to keep
  2. Remove the markers <<<, ===, >>>
  3. git add . and git commit

If something failed

ErrorCauseSolution
CONFLICTSame lines editedResolve manually
not a git repositoryOutside repocd to correct directory
rejectedRemote changesgit pull first

Apprentice level complete!

You've finished the Apprentice level. Now you have the basics for:

  • Using the terminal
  • Version control with Git
  • Consuming APIs
  • Creating scripts
  • Using Docker

โ†’ Chat with Web UI โ€” Start Cook level