Extra: Getting Started with GitHub
What is Git and GitHub?
Git is a distributed version control system that tracks changes in your code over time. Think of it as a sophisticated "undo" system that remembers every change you've ever made to your files.
GitHub is a cloud-based hosting service for Git repositories. It adds collaboration features like pull requests, issues, and project management tools on top of Git. Think of it as Google Drive for code, but with powerful version control and collaboration features.
Why use Version Control?
History Tracking: See who changed what and when
Backup: Your code is stored in multiple places
Collaboration: Multiple people can work on the same project
Branching: Experiment without breaking the main code
Rollback: Undo mistakes easily
Part 1: Setting up your GitHub account
If you Create a GitHub account go to github.com click the "Sign up" button and complete registration
Part 2: Installing and Configuring Git
2.1 Install Git on your computer
Windows Installation:
Download Git
Visit git-scm.com
Click "Download for Windows"
The download should start automatically
Run the Installer
Double-click the downloaded
.exefileImportant settings during installation:
Default editor: Choose your preferred text editor (VS Code recommended for beginners)
PATH environment: Select "Git from the command line and also from 3rd-party software"
Line ending conversions: Choose "Checkout Windows-style, commit Unix-style"
Terminal emulator: "Use MinTTY"
Default branch name: "main" (GitHub's new standard)
Keep other settings as default
Verify installation
Open Command Prompt or Git Bash
Type:
git --versionYou should see something like:
git version 2.40.0
Mac Installation:
Check if Git is Pre-installed
If you see a version number, Git is already installed
If not, continue with installation
Install via Homebrew (Recommended)
Alternative: Install via Xcode
Install Xcode Command Line Tools
Linux Installation:
Ubuntu/Debian:
2.2 Configure Git
After installation, you must configure Git with your identity. This information is attached to every commit you make.
Part 3: Authentication Methods
3.1 Understanding authentication options
GitHub offers several authentication methods. As of 2021, password authentication for Git operations was deprecated for security reasons. You now have two main options:
Personal Access Tokens (PAT) - Easier for beginners
SSH Keys - More secure and convenient long-term
3.2 Method 1: Personal Access Token (PAT) authentication
Creating a Personal Access Token:
Navigate to token settings
Log into GitHub
Click your profile picture → Settings
Scroll down to "Developer settings" in the left sidebar
Click "Personal access tokens" → "Tokens (classic)"
Click "Generate new token" → "Generate new token (classic)"
Configure your token
Note: Give it a descriptive name (e.g., "Personal Laptop Token")
Expiration: Select duration (90 days recommended for security)
Select scopes: For basic operations, check:
✅ repo (Full control of private repositories)
✅ workflow (Update GitHub Action workflows)
✅ write:packages (Upload packages to GitHub Package Registry)
✅ delete:packages (Delete packages from GitHub Package Registry)
Click "Generate token"
Save your token
IMPORTANT: Copy the token immediately!
You won't be able to see it again
Store it securely (password manager recommended)
Using your token
When cloning a private repository or pushing changes:
Storing token credentials (Optional)
To avoid entering your token repeatedly:
Windows:
Mac:
Linux:
3.3 Method 2: SSH Key Authentication (Recommended)
SSH keys provide a more secure and convenient way to authenticate. Once set up, you won't need to enter credentials for each operation.
Step 1: Check for existing SSH keys
If you see these files, you may already have SSH keys. You can use existing ones or create new ones.
Step 2: Generate a new SSH key pair
During key generation:
Press Enter to accept default file location
Enter a passphrase (recommended for security)
Confirm the passphrase
Your key pair is generated!
Understanding what was created:
Private key:
~/.ssh/id_ed25519(NEVER share this!)Public key:
~/.ssh/id_ed25519.pub(This goes to GitHub)
Step 3: Add SSH key to SSH agent
The SSH agent manages your keys and passphrases.
Mac/Linux:
Windows (Git Bash):
Step 4: Copy your public key
Mac:
Linux:
Windows (PowerShell):
Windows (Git Bash):
Step 5: Add SSH Key to GitHub
Go to GitHub.com and log in
Click profile picture → Settings
Click "SSH and GPG keys" in sidebar
Click "New SSH key"
Title: Enter descriptive name (e.g., "Personal MacBook Pro")
Key type: Keep as "Authentication Key"
Key: Paste your public key
Click "Add SSH key"
Confirm with your GitHub password if prompted
Step 6: Test your SSH connection
Step 7: Update repository URLs to use SSH
If you've already cloned repositories using HTTPS, update them to use SSH:
Part 4: Basic GitHub workflow
4.1 Creating a new repository
On GitHub (Remote):
Navigate to repository creation
Click "+" icon in top right corner
Select "New repository"
Configure repository settings
Repository name: Use lowercase with hyphens (e.g.,
my-awesome-project)Description: Brief explanation of your project
Visibility:
Public: Anyone can see
Private: Only you and collaborators can see
Initialize repository:
✅ Add a README file (recommended)
Add .gitignore: Select template for your language/framework
Choose a license: MIT for open source, or leave blank
Click "Create repository"
Locally (on your computer):
The above actions will overwrite the README.md file that was created when creating the repo. Also, the .gitignore file won't be pulled from the repo.
To avoid this, you can follow the simplified steps:
4.2 Cloning a Repository
Cloning creates a local copy of a remote repository:
4.3 Essential Git commands
Checking repository status
Adding files to staging area
The staging area is where you prepare changes before committing:
Committing changes
Working with Remotes
Pushing changes
Pulling and Fetching changes
4.4 Understanding Git's three states
Files in a Git repository can be in one of three states:
Modified: You've changed the file but haven't staged it
Staged: You've marked the file to go into next commit
Committed: The data is safely stored in your local database
Part 5: Branching and Merging
5.1 Understanding Branches
Branches allow you to develop features isolated from the main codebase. Think of them as parallel universes for your code.
5.2 Merging Branches
Part 6: Team Collaboration Example
6.1 A Real-World Scenario
Let's walk through a typical day for two developers, Alice and Bob, working on an e-commerce website.
Initial Setup
Repository Structure:
Day 1: Alice Works on Shopping Cart
Day 1: Bob Works on User Authentication
Day 2: Creating Pull Requests
Alice's Pull Request:
Alice goes to GitHub repository page
Clicks "Pull requests" → "New pull request"
Selects base:
main← compare:feature/shopping-cartAdds title: "Add shopping cart functionality"
Adds description:
Assigns Bob as reviewer
Clicks "Create pull request"
Bob Reviews Alice's Code:
Bob's Pull Request:
Bob creates a similar pull request for his authentication feature.
Day 3: Handling Merge Conflicts
Alice's PR gets merged first. Now Bob needs to update his branch:
6.2 Best Practices for Team Collaboration
Branch Naming Conventions
Commit Message Standards
Part 7: Restoring Files and Undoing Changes
7.1 Restoring a Single File
From the Last Commit
From Staging Area
7.2 Restoring the Entire Repository
To a Previous State
Creating a Backup Before Reset
7.3 Recovering Lost Commits
7.4 Viewing File History
Part 8: Advanced Features and Best Practices
8.1 The .gitignore File
Create a .gitignore file to exclude files from version control:
Global .gitignore
8.2 Stashing Changes
Save work in progress without committing:
8.3 Cherry-Picking Commits
Apply specific commits from one branch to another:
8.4 Interactive Rebase
Clean up commit history before merging:
8.5 Git Aliases for Efficiency
Part 9: GitHub-Specific Features
9.1 Issues
Issues track tasks, bugs, and feature requests:
Creating an Issue:
Go to repository → "Issues" → "New issue"
Add descriptive title
Use markdown for formatting
Assign labels (bug, enhancement, documentation)
Assign to team members
Link to project boards
Issue Templates: Create
.github/ISSUE_TEMPLATE/directory with templates:
9.2 Pull Request Templates
Create .github/pull_request_template.md:
9.3 GitHub Actions (CI/CD)
Create .github/workflows/main.yml:
9.4 GitHub Pages
Host static websites directly from repositories:
Enable GitHub Pages:
Go to Settings → Pages
Select source branch (usually
mainorgh-pages)Select folder (
/rootor/docs)Save
Access your site:
URL:
https://username.github.io/repository-name/
9.5 Project Boards
Organize work with Kanban-style boards:
Create a Project:
Go to Projects → New Project
Choose template (Basic Kanban, Automated Kanban)
Add columns: To Do, In Progress, Review, Done
Automation:
Auto-move issues when PR created
Auto-close issues when PR merged
Auto-archive completed items
Last updated
Was this helpful?