DEV Community

Stacy Omwoyo
Stacy Omwoyo

Posted on

Git for Beginners.

What is Git, How to use it and Why version control matters.

If you're new to tech or programming like me, then you've probably come across phrases like:

Did you commit your changes?
Push it to GitHub.
Pull the latest version.

And honestly, it feels like you were left out of an inside joke.
This article explains Git, GitHub, and Version control in layman's terms: why they matter, what they do, and how to use them as a complete beginner.

What is Version Control?

Version Control is a system that tracks your changes over time.
It allows you to:

  1. See what changed, when, and why

  2. Go back to a previous version safely

  3. Work with others without overwriting each other's work

  4. Experiment without fear of breaking everything

This is where Git comes in.

What is Git ?

Git is a version control tool that helps you save, track and manage changes to your project over time.
Instead of creating multiple messy files, Git:

  • Records every meaningful change

  • Saves it with a message explaining what you did

  • Lets you rewind to any point in time: time travel within your project

  • Scales from solo projects to global teams

How to push code to GitHub as a beginner

Pushing means sending your local project to GitHub

GitHub is an online platform that stores Git projects. It makes sharing and collaboration easier

Step 1: Create a new repository on GitHub

  • Go to GitHub.com
  • Create a new repository

  • Copy the repository URL

Step 2: Connect to your local project

  • Inside your Project folder on GitHub
git init

Enter fullscreen mode Exit fullscreen mode

This code tells Git to start tracking this project.

Step 3: Add everything in the folder

git add.

Enter fullscreen mode Exit fullscreen mode

Step 4: Commit your Changes

git commit -m "Added data cleaning script."

Enter fullscreen mode Exit fullscreen mode

Step 5: Copy the Repository URL from GitHub

https://github.com/yourusername/repository-name.git

Enter fullscreen mode Exit fullscreen mode

Step 6: Run

git branch -M main
git remote add origin https://github.com/yourusername/repository-name.git

Enter fullscreen mode Exit fullscreen mode

Step 7: Push your code

git push -u origin main

Enter fullscreen mode Exit fullscreen mode

Et Voila, your code is now on GitHub

From here on out, the next time you make changes, all you need is the code below:

git add.
git commit -m "Describe what you changed."
git push

Enter fullscreen mode Exit fullscreen mode

How to Pull code from Git

Now we will tackle how to pull code; where pulling is Getting the latest version of a project

If you don't have the project or this is your first time: use clone

Copy the repository link from GitHub. It often looks like this:

https://github.com/username/repo-name.git

Enter fullscreen mode Exit fullscreen mode

Run the code

git clone https://github.com/username/repo-name.git

Enter fullscreen mode Exit fullscreen mode

By doing this, you:
-Download the project
-Set up Git automatically
-Connects to GitHub

If you already have the project on your computer, then use Pull:

Go into the project folder on Bash

cd repo-name

Enter fullscreen mode Exit fullscreen mode

Pull the latest changes

git pull

Enter fullscreen mode Exit fullscreen mode

By doing this, you pull the latest updates from GitHub and merge them into your local files.

Cloning applies when getting the project for the first time
Pulling applies when updating an existing project

How to track projects using Git.

Each time you work on your project, you will repeat this cycle:

Check what changed

git status

Enter fullscreen mode Exit fullscreen mode

This tells you:
-Which files were modified
-Which files are new
-What is not yet tracked
This, simply put, is your dashboard.

Stage the changes:
To stage everything, use this code

git add.

Enter fullscreen mode Exit fullscreen mode

To stage a specific file, use this code.

git add filename.py
Enter fullscreen mode Exit fullscreen mode

This tells git what you want to save.

Commit the changes:

git commit -m "Describe what you changed."

Enter fullscreen mode Exit fullscreen mode

This is like saving a checkpoint in a game

View project history:

git log

Enter fullscreen mode Exit fullscreen mode

This shows:

  • All past commits
  • Who made them
  • When they were made

Breaking the giant into smaller, bite-sized pieces made it less scary and way simpler to digest and follow through. At its core, Git aims to protect your work, track your progress, and facilitate collaboration without chaos.

Whether you are learning software development, data science, analytics or working on research projects, Version Control isn't optional; it's a superpower.

Top comments (0)