DEV Community

Barbara Morara
Barbara Morara

Posted on

A Beginner’s Guide to Version Control with Git: Tracking, Pushing, and Pulling Code

A problem that programmers, especially beginners, often encounter is:
you make changes to the code, something goes wrong, and you would like to go back to a previous state. That is where a “version control” tool comes in to help you.
In this article, you will learn:
-What version control is and why it is important
-Git Changes Tracking
-How to push code on GitHub
-How to pull code from GitHub

What Is Version Control?
Version Control is the process wherein changes that have been made to files are tracked. With versioning, you have the ability to:
-Record a history of your work
-See what was changed and when
-Restore previous versions of code
-Work together with others without overwriting their work

What Is Git?
Git is a version control system that you install and operate from your computer. It assists you with:
-Monitoring changes made in files
-Save copies of your project (known as "commits")
-Working Offline
-Manage your project effectively
Git operates locally. This means all the changes occur on your personal machine.

What Is GitHub?
GitHub is an online hosting service used for storing Git repositories. It enables you to:
-Online code backups
-Collaborate on projects with others
-Work together on team projects

Key Git Concepts for Beginners

Repository (Repo): A project folder managed with Git
Commit: A saved snapshot of changes
Staging Area: This refers to where changes to be committed to the project's source code will be
Push: Code Uploads to GitHub
Pull: Downloading updated code from GitHub

Tracking Changes with Git

To see the state of your files, use:

git status

This indicates which files have been updated or are ready to be committed.

To prepare files for saving, add them to the staging area:
git add .

To save the changes permanently, create a commit:
git commit -m "Describe what changed"

In a commit message, you should describe the update you implemented.

Pushing Code to GitHub

After committing, however, your changes exist only on your own computer.
To upload the files to GitHub,use:
git push

Pulling Code from GitHub

If an update is done on GitHub, the local project could become stale.
To update it, run:
git pull

Git can appear intimidating at first, but learning the fundamentals of version control, change tracking, pushing, and pulling code can make development a much safer and more organized process. Git can become a powerful and very simple tool if you practice using it frequently.

Happy coding

Top comments (0)