DEV Community

Cover image for The Git & GitHub Guide I Wish I Had Before Losing My University Project
Khadija sajid
Khadija sajid

Posted on

The Git & GitHub Guide I Wish I Had Before Losing My University Project

I Lost My University Project a Few Hours Before Demo Day — That’s How I Learned Git
A few years ago, I learned one of the most important lessons of my software engineering journey the hard way.

Just a few hours before my university project exhibition, I was fixing what seemed like a small bug. Instead of solving the problem, I accidentally corrupted a significant portion of my project's backend files.

I had no backup.

No version history.

No recovery plan.

At that time, Git and GitHub were just words I had heard from senior developers. I never thought I needed them.

That day, I could only demonstrate the frontend of my project while the backend remained broken.

The experience taught me something every developer eventually learns:

Your code is not truly safe until it is version-controlled.

This article is the guide I wish I had back then.


What Is Git?

Git is a distributed version control system.

In simple terms, Git tracks changes in your project over time.

Think of it as a timeline for your code.

Instead of saving files like:

  • project-final
  • project-final-v2
  • project-final-v2-latest
  • project-final-v2-latest-actual-final

Git maintains a complete history of every meaningful change.

Benefits:

  • Recover deleted code
  • Compare versions
  • Collaborate with others
  • Experiment safely
  • Track project history

What Is GitHub?

Many beginners think Git and GitHub are the same thing.

They are not.

Git = Version control software running on your computer.

GitHub = Cloud platform that hosts Git repositories.

Think of it this way:

Git is your notebook.

GitHub is the cloud storage where that notebook is safely stored and shared.


Why Every Developer Needs Git

Imagine these situations:

  • You accidentally delete important code.
  • A new feature breaks everything.
  • Your laptop crashes.
  • A teammate introduces a bug.
  • You want to return to a previous working version.

Without Git:

You panic.

With Git:

You simply restore a previous commit.


Installing Git

Windows:

Download Git from the official Git website.

Verify installation:

git --version
Enter fullscreen mode Exit fullscreen mode

Expected output:

git version 2.x.x
Enter fullscreen mode Exit fullscreen mode

Creating Your First Repository

Create a project folder:

mkdir my-project
cd my-project
Enter fullscreen mode Exit fullscreen mode

Initialize Git:

git init
Enter fullscreen mode Exit fullscreen mode

Output:

Initialized empty Git repository
Enter fullscreen mode Exit fullscreen mode

Git is now tracking this folder.


Understanding the Git Workflow

Most beginners struggle because they don't understand Git's three stages.

Working Directory

Where you create and edit files.

Staging Area

Where you prepare changes for saving.

Repository

Where Git permanently stores snapshots.

Workflow:

Edit Files
     ↓
git add
     ↓
Staging Area
     ↓
git commit
     ↓
Repository History
Enter fullscreen mode Exit fullscreen mode

Your First Commit

Create a file:

touch app.py
Enter fullscreen mode Exit fullscreen mode

Check status:

git status
Enter fullscreen mode Exit fullscreen mode

Stage the file:

git add app.py
Enter fullscreen mode Exit fullscreen mode

Commit changes:

git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

Congratulations.

You have created your first checkpoint.


Essential Git Commands

Check Status

git status
Enter fullscreen mode Exit fullscreen mode

Shows:

  • Modified files
  • Staged files
  • Untracked files

View History

git log
Enter fullscreen mode Exit fullscreen mode

Displays all commits.

Compact view:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Compare Changes

git diff
Enter fullscreen mode Exit fullscreen mode

Shows what changed before committing.


Remove File from Staging

git restore --staged filename
Enter fullscreen mode Exit fullscreen mode

Understanding Branches

A branch is an independent line of development.

Imagine building a new feature without touching the main project.

That's exactly what branches allow.

Create branch:

git branch login-feature
Enter fullscreen mode Exit fullscreen mode

Switch branch:

git checkout login-feature
Enter fullscreen mode Exit fullscreen mode

Modern shortcut:

git switch login-feature
Enter fullscreen mode Exit fullscreen mode

Create and switch:

git switch -c login-feature
Enter fullscreen mode Exit fullscreen mode

Why Branches Matter

Without branches:

You experiment directly on production code.

With branches:

You can make mistakes safely.

Professional developers rarely work directly on the main branch.


Merging Branches

After finishing a feature:

Switch to main:

git switch main
Enter fullscreen mode Exit fullscreen mode

Merge feature:

git merge login-feature
Enter fullscreen mode Exit fullscreen mode

Git combines both histories.


Understanding Merge Conflicts

Conflicts occur when two versions modify the same lines.

Example:

Developer A changes line 10.

Developer B changes line 10.

Git cannot decide automatically.

You must manually choose which version to keep.

This is normal.

Even experienced engineers handle merge conflicts regularly.


Connecting Git to GitHub

Create a repository on GitHub.

Connect local repository:

git remote add origin repository-url
Enter fullscreen mode Exit fullscreen mode

Verify:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Push Code to GitHub

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Your code is now stored online.

This single command could have saved my university project years ago.


Clone Existing Repositories

Copy a repository:

git clone repository-url
Enter fullscreen mode Exit fullscreen mode

Git downloads the entire project history.


Pull Latest Changes

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Updates your local project.


Forking Open Source Projects

Forking creates your own copy of someone else's repository.

Typical workflow:

  1. Fork repository
  2. Clone fork
  3. Create branch
  4. Make changes
  5. Push changes
  6. Open Pull Request

This is how many developers contribute to open source.


Pull Requests

A Pull Request (PR) is a request to merge changes.

Benefits:

  • Code review
  • Discussion
  • Collaboration
  • Quality assurance

Professional teams rely heavily on PRs.


Git Ignore

Some files should never be tracked.

Examples:

  • Passwords
  • API keys
  • Build files
  • Temporary files

Create:

.gitignore
Enter fullscreen mode Exit fullscreen mode

Example:

node_modules/
.env
dist/
Enter fullscreen mode Exit fullscreen mode

Commit Message Best Practices

Bad:

fixed stuff
Enter fullscreen mode Exit fullscreen mode

Good:

Add user authentication system
Enter fullscreen mode Exit fullscreen mode

Great commits tell a story.

Future you will appreciate them.


GitHub Features Every Developer Should Use

Issues

Track bugs and tasks.

Projects

Manage development workflows.

Discussions

Community conversations.

Actions

Automate testing and deployment.

Releases

Publish stable versions.


GitHub Actions

GitHub can automatically:

  • Run tests
  • Build projects
  • Deploy applications

Every time code is pushed.

This is called CI/CD.

A basic workflow:

name: Test Project

on: push

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
Enter fullscreen mode Exit fullscreen mode

Common Beginner Mistakes

Not Committing Frequently

Commit small changes often.

Working Only on Main

Use feature branches.

Forgetting .gitignore

Never upload secrets.

Ignoring Pull Requests

Code reviews improve quality.

No Remote Backup

Always push to GitHub.


From Beginner to Professional

A beginner uses Git to save code.

An intermediate developer uses Git to collaborate.

An advanced engineer uses Git to manage complex software systems.

The commands are important.

The mindset is more important.

Version control is not about memorizing commands.

It is about building with confidence.


Final Thoughts

The day I lost my university project taught me a lesson I will never forget.

Git is not just a developer tool.

GitHub is not just a website.

Together, they form a safety net that protects your work, enables collaboration, and gives you the confidence to experiment without fear.

If you are learning software development today, start using Git and GitHub immediately.

Trust me.

It is far better to learn from this article than from losing a project a few hours before demo day.

Top comments (0)