top of page

Please contact nnmarieconsulting@gmail.com for displaying your ads on our website

Homepage

Everything You Need to Know About Git and GitHub and How to Use Them

Writer: Nhung Nguyen
Nhung Nguyen
Jun 26
5 min read


Introduction

If you're planning to become a software developer, data scientist, DevOps engineer, or even a technical project manager, Git and GitHub are two essential tools you must learn. Nearly every modern software project—from small personal websites to enterprise applications developed by companies like Google, Microsoft, and Netflix—uses Git for version control and GitHub for collaboration.

This guide will explain everything from the basics to advanced workflows, complete with practical examples and best practices.

Table of Contents

  1. What is Version Control?

  2. What is Git?

  3. What is GitHub?

  4. Git vs GitHub

  5. Installing Git

  6. Git Configuration

  7. Creating Your First Repository

  8. Understanding the Git Workflow

  9. Essential Git Commands

  10. Branches Explained

  11. Merging Branches

  12. Resolving Merge Conflicts

  13. Connecting Git with GitHub

  14. Working with Remote Repositories

  15. Pull Requests

  16. GitHub Issues

  17. GitHub Projects

  18. GitHub Actions (CI/CD)

  19. Git Ignore

  20. Git Tags & Releases

  21. Forking Repositories

  22. Git Workflow Strategies

  23. Best Practices

  24. Common Mistakes

  25. Frequently Asked Questions

What is Version Control?

Imagine writing a book.

You save versions like:


Book_v1.docx

Book_v2.docx

Book_v3_Final.docx

Book_v3_Final_Final.docx

Book_v3_Really_Final.docx


Eventually, nobody knows which file is the latest.

Version Control solves this problem.

It records:

  • Every change

  • Who made the change

  • When it happened

  • Why it happened

  • Ability to restore previous versions

What is Git?

Git is a Distributed Version Control System (DVCS) created by Linus Torvalds in 2005.

Git tracks every change made to files.

Instead of saving multiple copies, Git stores snapshots of your project over time.

Benefits include:

  • Track changes

  • Undo mistakes

  • Collaborate with others

  • Create experimental features safely

  • Restore older versions

What is GitHub?

GitHub is a cloud platform that hosts Git repositories online.

Think of Git as Microsoft Word.

GitHub is like Google Drive for Git repositories.

GitHub provides:

  • Cloud backup

  • Team collaboration

  • Pull Requests

  • Code reviews

  • Issue tracking

  • CI/CD automation

  • Project management

Git vs GitHub

Git

GitHub

Version control software

Cloud hosting service

Runs on your computer

Runs on the Internet

Free and open source

Free and paid plans

Tracks file changes

Stores Git repositories

Command-line tool

Web application

Installing Git

Windows

Download Git from:

Run the installer with default settings.

Verify installation:

git --version

Example:

git version 2.45.0

Configure Git

Set your identity.

git config --global user.name "John Smith"
git config --global user.email "john@email.com"

View settings:

git config --list

Create Your First Repository

Create a project.

MyWebsite/

Initialize Git.

git init

Output:

Initialized empty Git repository

Now Git starts tracking your project.

Git Workflow

The Git workflow has four stages.


Working Directory

↓

git add

↓

Staging Area

↓

git commit

↓

Local Repository

↓

git push

↓

GitHub Repository


Git File States

Git files move through different states.


Untracked


↓


Modified


↓


Staged


↓


Committed


Essential Git Commands

Check Status

git status

Shows:

  • modified files

  • staged files

  • untracked files

Add Files

Single file

git add app.js

Everything

git add .

Commit

git commit -m "Add login page"

Always write meaningful messages.

Good:

Fix login validation

Bad:

Update

View History

git log

Compact version:

git log --oneline

Undo Changes

Discard file changes

git restore app.js

Undo staged file

git restore --staged app.js

Undo last commit

git reset HEAD~

Branches

A branch is an independent line of development.

Main branch

main

Feature branch

feature/login

Bug fix

bugfix/payment

Create Branch

git branch feature-login

Switch branch

git checkout feature-login

Or

git switch feature-login

Create and switch

git checkout -b feature-login

Merge Branch

Return to main.

git checkout main

Merge.

git merge feature-login

Merge Conflicts

Suppose two developers modify the same line.

Git cannot decide automatically.

Example


<<<<<<< HEAD

Login Button

=======

Sign In Button

>>>>>>> feature

Resolve manually.


Then:

git add .
git commit

Connect to GitHub

Create a repository on GitHub.

Then connect.

Verify

git remote -v

Push to GitHub

First push

git push -u origin main

Later

git push

Clone Repository

Downloads entire project history.

Pull Latest Changes

git pull

Equivalent to:

Fetch+Merge

Fetch Without Merge

git fetch

Downloads updates only.

Pull Requests

A Pull Request (PR) is a request to merge code into another branch.

Workflow

Developer


↓


Create Branch


↓


Commit Changes


↓


Push Branch


↓


Open Pull Request


↓


Review


↓


Merge


GitHub Issues

Issues are used for:

  • Bugs

  • Tasks

  • Features

  • Improvements

Example

#52Improve search speed

GitHub Projects

GitHub Projects provides Kanban boards.

Example


To Do


↓


In Progress


↓


Review


↓


Done


Useful for Agile development.

GitHub Actions

GitHub Actions automates workflows.

Example


Push Code


↓


Run Tests


↓


Build Application


↓


Deploy


Example workflow

name: Build


on: push


jobs:

test:

runs-on: ubuntu-latest

.gitignore

Ignore files Git should never track.

Example

node_modules/.envdist/*.log

Never commit:

  • passwords

  • API keys

  • certificates

  • secrets

Tags

Tags mark important versions.

Example


v1.0


v2.0


v3.1


Create

git tag v1.0

Push

git push origin v1.0

Forking

Forking copies another person's repository into your own GitHub account.

Useful for:

  • Open-source contributions

  • Experimenting safely

Workflow


Original Repo


↓


Fork


↓


Clone


↓


Modify


↓


Pull Request

Popular Git Workflows

Feature Branch Workflow

main


├── feature-login


├── feature-payment


└── feature-profile


Each feature has its own branch.

Git Flow

Branches:

main


develop


feature


release


hotfix

Suitable for enterprise software.

GitHub Flow

main


↓


Feature Branch


↓


Pull Request


↓


Review


↓


Merge


Simple and popular.

Best Practices

✅ Commit frequently

✅ Write meaningful commit messages

✅ Pull before pushing

✅ Keep branches small

✅ Never commit secrets

✅ Review Pull Requests

✅ Use .gitignore

✅ Tag releases

✅ Protect the main branch

Common Mistakes

Forgetting to Pull

Always:

git pull

before:

git push

Committing Large Files

Use:

Git LFS

for videos and datasets.

Working Directly on Main

Instead:


main


↓


feature branch


↓


Pull Request


↓


Merge

Bad Commit Messages

Bad

Fix stuff

Good

Fix null pointer exception during login

Real-World Development Workflow

A typical day for a software developer:

  1. Pull the latest changes:

    git pull origin main

  2. Create a feature branch:

    git checkout -b feature/user-profile

  3. Develop and test your code.

  4. Stage and commit changes:

    git add .


    git commit -m "Add user profile editing"

  5. Push the branch:

    git push origin feature/user-profile

  6. Open a Pull Request on GitHub.

  7. Address any review comments.

  8. Merge the Pull Request into main.

  9. Delete the feature branch after merging.

Frequently Asked Questions

Is Git the same as GitHub?

No. Git is the version control software, while GitHub is a cloud platform for hosting Git repositories and collaborating with others.

Do I need GitHub to use Git?

No. Git works entirely on your local machine. GitHub is optional but highly recommended for backup and teamwork.

Can I recover deleted code?

Usually yes. If the changes were committed, Git's history often allows you to restore previous versions.

What is the difference between git fetch and git pull?

  • git fetch downloads changes from the remote repository without modifying your current branch.

  • git pull downloads changes and merges them into your current branch.

When should I create a new branch?

Create a new branch for every new feature, bug fix, or experiment. This keeps the main branch stable and makes collaboration easier.

Final Thoughts

Git and GitHub have become the industry standard for modern software development. Whether you're working alone or collaborating with a global team, mastering these tools is one of the most valuable skills you can acquire.

Start with the basics—initializing repositories, committing changes, branching, and pushing to GitHub. As you gain experience, explore advanced topics such as rebasing, cherry-picking, Git hooks, submodules, and GitHub Actions for continuous integration and deployment (CI/CD).

By following best practices like committing frequently, writing clear commit messages, using feature branches, and reviewing code through Pull Requests, you'll build a workflow that is reliable, collaborative, and scalable for projects of any size.

With consistent practice, Git and GitHub will become an indispensable part of your daily development toolkit, helping you manage code confidently, collaborate effectively, and deliver higher-quality software.


Resources: internet

Comments


bottom of page