The Open Engine: Git & GitHub Mastery
Unlocking the world of professional collaboration. Learn the tools that power the global software engineering community.
What is Git & GitHub?
Before Git, developers used to email folders of code to each other. It was a nightmare. Git is a Version Control System (VCS), a tool that helps track changes in code and allows thousands of people to work on the same project simultaneously without breaking each other's work.
GitHub is the social layer on top of Git. It's where the world's most important software (like Linux, React, and Python) lives and grows.
- Repo (Repository): A folder where your project files and their version history are stored.
- Commit: A recorded point in your project's history representing saved changes.
Setup of Git
To start using Git, you need a terminal. On Windows, Git Bash is recommended alongside an editor like VS Code.
You can download Git from: https://git-scm.com/download/win
git --version # Verify Git installation
Basic Commands
Navigating the Terminal
cd [path] # Change directory
ls # List files in the current folder
ls -a # List all files, including hidden ones
Init Command
Used to create a new Git repository in your current folder.
git init
git remote add origin "link" # Connect local repo to remote
git remote -v # Verify remote connection
The Core Workflow
The fundamental process of contributing code follows this path:
GitHub Repo ➔ Clone ➔ Changes ➔ Add ➔ Commit ➔ Push
Clone & Status
Clone: Downloading a repository to your local machine.
git clone "project link" # Clone using HTTPS link from GitHub repo
Status: Displays the state of your working directory and staging area.
git status
File states transition between: untracked, modified, staged, unmodified.
Add, Commit & Push
Add: Adds new or changed files in your working directory to the Git staging area.
git add "file name" # Add a specific file
git add . # Add all current changes
Commit: It's the record of a change.
git commit -m "type your message"
Push: Upload local repository content to a remote repository.
git push origin main # Standard push command
git push -u origin main # Push and set upstream
Fearless Branching
In a professional environment, everyone makes their own copy to work on, called a Branch
(e.g., a feature branch diverging from main or master default branch). It's a
sandbox where you can experiment safely without affecting others.
git branch # Check branches
git branch -M main # Rename branch to 'main'
git checkout [branch name] # Navigate between branches
git checkout -b [new branch] # Create and switch to new branch
git branch -d [branch name] # Delete branch
Merging & Pull Requests
After finishing a feature, you need to bring changes back.
Way 1: Merge Commands
git diff [branch name] # Compare commits, branches, files, etc.
git merge [branch name] # Merge another branch into your current one
Way 2: Pull Request (PR)
A Pull Request lets you tell others about changes you've pushed. It's a conversation where you ask teammates to review your code.
Branch ➔ main (Sr Dev) ➔ PR Review
Resolving Merge Conflicts: An event that takes place when Git is unable to automatically resolve differences in code between two commits. Typically resolved during a PR review or a Git merge manually.
Keeping Sync: Pull & Fork
Pull: Used to fetch and download content from a remote repo and immediately update the local repo to match that content.
git pull origin main
Fork: A fork is a rough copy. It's a new repository that shares code and visibility settings with the original "upstream" repository. Ideal for contributing to Open Source projects you don't own.
Undoing Changes
Mistakes happen. Here's how to go back in time safely.
git log # Check history to find commit hash
# Case 1: Staged changes (Unstage)
git reset [file name]
git reset
# Case 2: Committed changes (undo 1 recent commit)
git reset HEAD~1
# Case 3: Committed changes (discard changes entirely to a commit)
git reset [commit hash]
git reset --hard [commit hash] # WARNING: Deletes uncommitted work!
With these commands, you have the foundational power of Git and GitHub at your fingertips. Now go build something amazing!