Git and GitHub for Beginners: The Complete Guide Every Developer Needs

Every professional developer uses Git and GitHub daily. Whether you are building a personal project, contributing to open source, or working on a team at an IT company in Kathmandu or Pokhara, version control is a non-negotiable skill. Yet many beginners in Nepal skip learning Git properly, relying on manually copying project folders or emailing code files back and forth — habits that cause serious problems as projects grow.
This guide covers everything you need to know about Git and GitHub as a beginner. You will learn the essential commands, understand branching and merging, and master the collaboration workflows that employers expect you to know before your first developer job.
What Is Git and Why Do Developers Need It?
Git is a free version control system that tracks every change you make to your code, allowing you to revert mistakes, collaborate with others, and maintain a complete history of your project's evolution.
Think of Git like a save system in a video game. Every time you "commit" your code, Git saves a snapshot of your entire project. If you break something, you can go back to any previous save point. Without Git, a single mistake could mean losing hours or days of work.
Git was created by Linus Torvalds (the creator of Linux) in 2005. Today, it is used by virtually every software company worldwide, including all major IT companies in Nepal.
Here is what Git lets you do:
- Track every change to every file in your project
- Revert to any previous version of your code
- Work on new features without affecting the main codebase
- Collaborate with other developers without overwriting each other's work
- Maintain a complete audit trail of who changed what and when
Installing Git is straightforward:
# Check if Git is already installed
git --version
# Install on Ubuntu/Linux
sudo apt-get install git
# Install on macOS
brew install git
# On Windows, download from https://git-scm.com/download/win
After installation, configure your identity:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
What Is GitHub and How Is It Different from Git?
GitHub is a cloud-based platform that hosts your Git repositories online, enabling collaboration, code sharing, and project management — while Git is the tool that runs locally on your computer.
| Feature | Git | GitHub |
|---|---|---|
| What it is | Version control software | Cloud hosting platform |
| Where it runs | Locally on your computer | Online (github.com) |
| Purpose | Track code changes | Share and collaborate |
| Cost | Free | Free (with paid tiers) |
| Internet needed | No | Yes |
| Created by | Linus Torvalds | Tom Preston-Werner |
| Alternatives | None (it is the standard) | GitLab, Bitbucket |
GitHub is essentially a social network for code. Your GitHub profile acts as a portfolio that employers can review. Many IT companies in Nepal check candidates' GitHub profiles during the hiring process. A GitHub profile with well-documented projects and consistent commit history demonstrates your skills better than any resume.
Other features GitHub provides:
- Issues: Track bugs and feature requests
- Pull Requests: Propose and review code changes
- Actions: Automate testing and deployment
- Pages: Host static websites for free
- Copilot: AI-powered coding assistant
How Do You Create Your First Git Repository?
Initialize a new Git repository by running git init in your project folder, then add files with git add, and save your first snapshot with git commit — these three commands start every project.
Here is the complete workflow for creating your first repository:
# Step 1: Create a new project folder
mkdir my-first-project
cd my-first-project
# Step 2: Initialize Git in this folder
git init
# Output: Initialized empty Git repository in /my-first-project/.git/
# Step 3: Create a file
echo "# My First Project" > README.md
# Step 4: Check the status of your repository
git status
# Output: Untracked files: README.md
# Step 5: Stage the file for commit
git add README.md
# Step 6: Commit the file with a descriptive message
git commit -m "Add README with project title"
# Step 7: Check the log to see your commit
git log --oneline
# Output: a1b2c3d Add README with project title
Now connect it to GitHub:
# Step 8: Create a repository on GitHub (via website or CLI)
# Then link your local repo to GitHub
git remote add origin https://github.com/yourusername/my-first-project.git
# Step 9: Push your code to GitHub
git branch -M main
git push -u origin main
Understanding the three areas of Git is crucial:
- Working Directory: Your actual files on disk — where you write code
- Staging Area: Files you have marked to include in the next commit (
git add) - Repository: The committed history stored by Git (
git commit)
Working Directory → Staging Area → Repository
(edit files) (git add) (git commit)
What Are the Essential Git Commands Every Beginner Must Know?
Master these 15 commands and you will handle 95% of daily Git tasks: init, clone, status, add, commit, push, pull, branch, checkout, merge, log, diff, stash, reset, and remote.
Here is a reference table with examples:
| Command | Purpose | Example |
|---|---|---|
git init |
Start a new repository | git init |
git clone |
Copy a remote repository | git clone https://github.com/user/repo.git |
git status |
Check file states | git status |
git add |
Stage files | git add index.html or git add . |
git commit |
Save a snapshot | git commit -m "Fix login bug" |
git push |
Upload to remote | git push origin main |
git pull |
Download and merge | git pull origin main |
git branch |
List/create branches | git branch feature-login |
git checkout |
Switch branches | git checkout feature-login |
git merge |
Combine branches | git merge feature-login |
git log |
View commit history | git log --oneline |
git diff |
See changes | git diff |
git stash |
Temporarily save changes | git stash |
git reset |
Undo changes | git reset HEAD~1 |
git remote |
Manage remote connections | git remote -v |
Common workflows using these commands:
# Daily workflow: Make changes, stage, commit, push
git status # See what changed
git add . # Stage all changes
git commit -m "Add user authentication feature"
git push origin main # Push to GitHub
# View what changed before committing
git diff # Unstaged changes
git diff --staged # Staged changes
# Undo the last commit (keep changes)
git reset --soft HEAD~1
# Temporarily save work-in-progress
git stash # Save current changes
git stash pop # Restore saved changes
# View commit history
git log --oneline --graph # Compact visual history
How Does Branching Work in Git?
Branching creates an independent copy of your codebase where you can develop features or fix bugs without affecting the main code, then merge your changes back when they are ready and tested.
Branching is what makes Git truly powerful. Think of it like creating a parallel universe for your code — you can experiment freely, and if things go wrong, the main codebase remains untouched.
# Create and switch to a new branch
git checkout -b feature/user-profile
# This is shorthand for:
git branch feature/user-profile
git checkout feature/user-profile
# Work on your feature...
# Make changes to files
git add .
git commit -m "Add user profile page layout"
git commit -m "Add profile picture upload functionality"
# Switch back to main branch
git checkout main
# Merge your feature branch into main
git merge feature/user-profile
# Delete the branch after merging (cleanup)
git branch -d feature/user-profile
Common branching strategies:
| Strategy | Description | Best For |
|---|---|---|
| Feature Branching | One branch per feature | Small teams |
| Git Flow | Develop, release, and hotfix branches | Large projects |
| Trunk-Based | Short-lived branches, frequent merges | CI/CD teams |
| GitHub Flow | Feature branches + pull requests | Open source |
Branch naming conventions:
feature/login-page # New feature
bugfix/payment-error # Bug fix
hotfix/security-patch # Urgent fix
refactor/database-layer # Code improvement
When two people change the same lines in the same file, Git creates a merge conflict. Here is how to resolve one:
# After attempting to merge and hitting a conflict:
git merge feature-branch
# Output: CONFLICT in index.html
# Open the conflicted file — you will see:
<<<<<<< HEAD
<h1>Welcome to Our Site</h1>
=======
<h1>Welcome to Swift Academy</h1>
>>>>>>> feature-branch
# Edit the file to keep what you want:
<h1>Welcome to Swift Academy</h1>
# Stage the resolved file and commit
git add index.html
git commit -m "Resolve merge conflict in index.html"
What Are Pull Requests and How Do You Use Them?
A pull request (PR) is a GitHub feature that lets you propose changes from your branch, request code reviews from teammates, and discuss modifications before merging into the main codebase.
Pull requests are the standard way teams collaborate on GitHub. Here is the workflow:
# Step 1: Create a feature branch
git checkout -b feature/add-contact-form
# Step 2: Make your changes and commit
git add .
git commit -m "Add contact form with validation"
# Step 3: Push your branch to GitHub
git push origin feature/add-contact-form
# Step 4: Go to GitHub and create a Pull Request
# Or use GitHub CLI:
gh pr create --title "Add contact form" --body "This PR adds a contact form with email validation"
A good pull request includes:
- A clear title describing the change
- A description explaining what and why
- Reference to any related issues
- Screenshots for UI changes
- Small, focused changes (not 50 files at once)
PR Review Process:
- Developer creates PR from feature branch
- Reviewers examine the code and leave comments
- Developer addresses feedback and pushes updates
- Reviewers approve the PR
- PR is merged into the main branch
This process catches bugs, ensures code quality, and spreads knowledge across the team. Even if you are working solo, creating PRs helps you review your own code before merging.
How Should You Write Good Commit Messages?
Good commit messages follow the pattern of a short imperative summary under 50 characters, optionally followed by a blank line and detailed explanation — this makes project history readable and searchable.
Bad vs good commit messages:
# BAD commit messages
git commit -m "fixed stuff"
git commit -m "update"
git commit -m "asdfgh"
git commit -m "changes"
# GOOD commit messages
git commit -m "Fix payment gateway timeout on slow connections"
git commit -m "Add user authentication with JWT tokens"
git commit -m "Refactor database queries to reduce load time by 40%"
git commit -m "Update dependencies to patch security vulnerability"
The conventional commit format many teams follow:
# Format: type(scope): description
git commit -m "feat(auth): add Google OAuth login"
git commit -m "fix(cart): resolve quantity update bug"
git commit -m "docs(readme): update installation instructions"
git commit -m "refactor(api): simplify error handling middleware"
git commit -m "test(user): add unit tests for registration"
| Type | When to Use |
|---|---|
| feat | New feature |
| fix | Bug fix |
| docs | Documentation only |
| style | Formatting, no code change |
| refactor | Code change, no new feature or fix |
| test | Adding or updating tests |
| chore | Maintenance tasks |
How Do You Set Up a Professional GitHub Profile?
A professional GitHub profile includes a profile README, pinned repositories with documentation, consistent commit activity, and contributions to open-source projects — this serves as your developer portfolio.
Create a profile README:
# Create a repo with the same name as your GitHub username
# For example, if your username is "prabi-dev"
# Create repo: prabi-dev/prabi-dev
# Add a README.md with:
# Hi, I am Prabi 👋
## About Me
- 🔭 Full Stack Developer from Pokhara, Nepal
- 🌱 Currently learning Next.js and Flutter
- 💬 Ask me about JavaScript, React, and Python
## Tech Stack



## GitHub Stats

Tips for a strong GitHub profile:
- Pin your best 6 repositories — choose projects that demonstrate different skills
- Write clear README files — every project should explain what it does and how to run it
- Commit regularly — the green contribution graph shows consistency
- Use proper .gitignore files — never commit node_modules, .env files, or compiled code
# Example .gitignore for a Node.js project
node_modules/
.env
.env.local
dist/
build/
*.log
.DS_Store
What Reddit and Developer Communities Say About Git and GitHub
Discussions on r/learnprogramming, r/webdev, and r/git consistently highlight:
-
"Learn Git from the command line first, not a GUI." Most experienced developers recommend understanding the terminal commands before using graphical tools like GitHub Desktop or VS Code's built-in Git features.
-
"You will mess up your Git history — and that is completely fine." Beginners often fear breaking things, but Git is designed so that almost nothing is truly irreversible. Learning to recover from mistakes is part of the process.
-
"Your GitHub profile IS your resume." Hiring managers and recruiters, including those at Nepali IT companies, frequently browse candidates' GitHub profiles. A green contribution graph and well-documented projects can compensate for lack of formal experience.
-
"Start using Git from day one, even for solo projects." Many Redditors regret not learning Git earlier. Even if you are the only developer, version control saves you from losing work and teaches habits essential for team environments.
Practical Takeaway: Git Commands Cheat Sheet
Save this workflow for your daily development:
# Starting a new project
git init
git remote add origin <repo-url>
# Daily workflow
git pull origin main # Get latest changes
git checkout -b feature/new-task # Create feature branch
# ... write code ...
git add . # Stage changes
git commit -m "feat: description" # Commit with clear message
git push origin feature/new-task # Push to GitHub
# Create Pull Request on GitHub
# After PR is merged
git checkout main
git pull origin main
git branch -d feature/new-task # Clean up
# Emergency commands
git stash # Save work temporarily
git log --oneline # Find a commit
git reset --soft HEAD~1 # Undo last commit (keep changes)
git checkout -- file.txt # Discard changes to a file
Start using these commands today. Create a GitHub account, push your first project, and make Git part of your daily coding routine.
Frequently Asked Questions
Is Git difficult to learn for complete beginners?
Git has a learning curve, but the basic commands (add, commit, push, pull) can be learned in a day. Most beginners become comfortable with daily Git workflows within 1-2 weeks of regular use. Focus on the 10-15 most common commands first and learn advanced features as you need them.
Can I use Git without GitHub?
Yes. Git is a standalone tool that works entirely on your local computer. GitHub is just one of many cloud platforms for hosting Git repositories. Alternatives include GitLab and Bitbucket. However, GitHub is the most popular platform and the one most employers expect you to use.
How often should I commit my code?
Commit whenever you complete a logical unit of work — a new feature, a bug fix, or a meaningful change. Most developers commit several times per day. Small, frequent commits are better than large, infrequent ones because they make it easier to track changes and revert specific modifications.
Do I need to pay for GitHub?
No. GitHub's free tier includes unlimited public and private repositories, GitHub Actions (2,000 minutes/month), and all essential features. The paid tiers (Pro, Team, Enterprise) add features like advanced code review tools and more Actions minutes, but beginners and most individual developers never need to pay.
What is a .gitignore file and why is it important?
A .gitignore file tells Git which files and folders to exclude from version control. This is critical for keeping sensitive data (API keys, passwords in .env files), large files (node_modules), and system files (.DS_Store) out of your repository. Every project should have a .gitignore file from the start.
Master Git and Modern Development at Swift Academy
Git and GitHub are essential skills for every developer role. At Swift Academy in Pokhara, our courses in Flutter, Next.js, Django, and Laravel integrate Git workflows from day one. You will learn version control as part of building real projects — the way professional teams actually work. Enroll today for just NPR 16,000 per course.
Related Articles
- How to Start Learning Coding in Nepal: A Complete Beginner's Guide for 2026
- What Is an API? A Simple Explanation for Non-Technical People and Beginners
- SQL vs NoSQL Databases: Which Should You Learn First as a Beginner?
Suggested Images
- Hero Image: Terminal window showing Git commands with a clean code editor in the background — alt text: "Git commands in terminal for beginners learning version control"
- Diagram: Visual flowchart showing the Git workflow from working directory to staging area to repository to remote — alt text: "Git workflow diagram showing add commit push cycle"
- Screenshot: A well-organized GitHub profile page with pinned repositories and contribution graph — alt text: "Professional GitHub profile example for developers"




