Git & GitHub: Complete Documentation
This guide explains what Git and GitHub are, how they relate, and how to work with them using the most common commands. It includes workflows for both individual and team-based development.
1. Understanding Git & GitHub
What is Git?
Git is a version control system (VCS) that allows developers to:
- Track changes in source code
- Revert to previous versions
- Work on different branches
- Collaborate without overwriting each other’s work
Git works locally on your machine.
What is GitHub?
GitHub is a remote hosting platform for Git repositories. It enables:
- Cloud storage of code
- Collaboration between team members
- Pull Requests (PRs)
- Issue tracking
- Project management
How They Work Together
You:
- Write code locally using Git
- Push changes to GitHub
- Collaborate via pull requests and remote branches
Git = tool on your computer GitHub = website that stores and shares your Git repository
2. Installing Git
Check if Git is installed:
git --version
If not installed, download from: https://git-scm.com/
3. Essential Git Concepts
Repository (repo)
A folder tracked by Git.
Commit
A saved version of your code.
Branch
A separate environment to develop features without breaking the main code.
Remote
A GitHub-hosted version of your repo.
Merge / Pull Request
Combining changes from different branches.
4. Basic Git Commands
Commonly used commands:
git init # Initialize a new repository
git clone url # Download a repo
git status # Check file status
git add . # Stage changes
git commit -m "msg" # Save changes
git push # Upload to GitHub
git pull # Get latest changes
git branch # List branches
git branch name # Create branch
git checkout name # Switch branch
git merge name # Merge branch into current
git log # View commit history
git diff # Compare changes
5. Workflow for Individual Work
Step-by-Step
git clone url
git add . # or: git add file_name
git commit -m "your message"
git push
Typical Workflow
- Edit files
- Stage changes →
git add - Commit them →
git commit - Push to GitHub →
git push
6. Team Workflow: Branching & Pull Requests
Below is the standard professional workflow.
Step 1: Create & Work on a Feature Branch
git clone url
# Create a new branch
git branch branch_name
# Set branch to track GitHub remote
git push -u origin branch_name
# Switch to the branch
git checkout branch_name
# Work + stage changes
git add . # or: git add file_name
git commit -m "your message"
git push
Step 2: Create a Pull Request (PR)
On GitHub:
- Open the repository
- Click Pull Requests → New Pull Request
- Select your branch as the source
- Add:
- Title
- Description
- Reviewers
- Submit PR
- Team reviews & approves
- Merge into
main
Step 3: Clean Up Branch & Update Local Main
# Move back to the main branch
git checkout main # or master / dev
# Delete the old local branch
git branch -D branch_name
# Confirm remaining branches
git branch
# Get the latest main code
git pull origin main
7. Common Collaboration Commands
Get updates from GitHub
git pull origin main
Fetch all branches
git fetch --all
Merge another branch into your working branch
git merge branch_name
Resolve merge conflicts
Git will mark conflicts in files with:
<<<<<<< HEAD
local changes
=======
remote changes
>>>>>>> branch_name
You must edit manually, then:
git add .
git commit
8. Git Best Practices
- Never commit directly to
main - Make small commits with meaningful messages
- Always pull before pushing
- Use branches for every feature or bug fix
- Review code via PR before merging
9. Git Commit Message Guidelines
Good commit messages:
feat: add login page
fix: resolve database connection issue
refactor: cleanup user auth function
docs: update README
10. Summary
Git helps you manage code locally. GitHub helps teams collaborate remotely. Most workflows revolve around:
- Branching
- Committing
- Pushing
- Creating Pull Requests
- Merging
Use the commands in this doc as a complete reference for everyday Git & GitHub work.
