DEV Community

Carobecky chepngeno
Carobecky chepngeno

Posted on

Understanding version control, pushing and pulling code and tracking changes using Git.

If you are new to programming and data analytics,keep your worries down.This article explains Git in a simple and practical way.By the end of this guide,you will grasp:

  • What version control is and it uses
  • What is git and how it works
  • How to push and pull code using git
  • How to track changes in your code
  • Beginner friendly common git commands

Version Control

This is a system that helps you:

  • Track changes and shows what changed,when and by whom
  • Go back to previous versions and undo mistakes
  • work on the same project with other people without overwriting each other's work.

Git

This is basically a version control system that runs on your computer ( a tool on your computer)
Git has three main areas:

  • Working Directory that is a normal folder where you edit files.
  • staging area where you select the changes you want to save.
  • Repository where commits (your project at a specific time) are stored permanently. Git helps you:
  • Show your work professionally
  • Collaborate effectively
  • Build a strong portfolio on Github

Github

This is an online platform that stores Git repositories.

Installing Git

How to check if it is installed:

git --version 
Enter fullscreen mode Exit fullscreen mode

if not, go to:

  • windows download and install Git from [git-scm.com](https://git-scm.com)
  • mac brew install git
  • linux sudo apt install git

Creating a Git repository

option 1. initialize git in an existing project

git init
Enter fullscreen mode Exit fullscreen mode

option 2. clone an existing repository

git clone
https://github.com/username/project-name.git
Enter fullscreen mode Exit fullscreen mode

Tracking changes with Git

To check file status,

git status 
Enter fullscreen mode Exit fullscreen mode

This shows;

  • New files
  • Modified files
  • Files ready to commit To add files to the staging area;
git add file_name
Enter fullscreen mode Exit fullscreen mode

Or add everything

git add .
Enter fullscreen mode Exit fullscreen mode

To commit changes;

git commit -m "describe what you changed"
Enter fullscreen mode Exit fullscreen mode

To view commit history;

git log
Enter fullscreen mode Exit fullscreen mode

Commit history shows:

  • Author
  • Dates
  • commit messages and IDs

Pushing Code

This means sending your local commits to a repository like Github.It helps

  • To back up your work online
  • To share your code
  • To collaborate with a team First time connecting:

git remote add origin
Enter fullscreen mode Exit fullscreen mode

To push code:


git push origin main
Enter fullscreen mode Exit fullscreen mode

origin means remote repository
main is the branch name

Pulling Code

This means getting the changes from the remote repository to your computer.This is done in order to;

  • Download updates made by team mates
  • Sync and merge your local code with the remote version

git pull origin main
Enter fullscreen mode Exit fullscreen mode

This is the comparison

Action Meaning
git push upload your changes
git pull download other's changes

Always pull before working and push when you are done.Also make sure to commit to allow Git to save your changes.
You don't need to know every Git command to get started. Master the basics:

  • git status
  • git add
  • git commit
  • git push
  • git pull With overtime practice, Git will become an efficient tool for your everyday use.

Top comments (0)