DEV Community

Wesley Clark
Wesley Clark

Posted on

How to push and pull code, track changes and understand version control using Git

Introduction

What is version control?

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

Why use Git

  1. Collaboration- Multiple people can work on the same project without overwriting each other's code.
  2. History- One can see who exactly changed what and why.
  3. Experimentation- One create branches to try new ideas without breaking the main project.

Tracking changes

Main areas of a Git project

  • Working directory- Where you are currently editing your files.
  • Staging area- Which changes you want to include in your next save point.
  • Local repository- Where Git permanently stores the history of your project.

Work flow

Modify a file in your directory
Stage the file(git add)
Commit the file(git commit)

Pushing code

When you have finished making "commits" on your computer and you want to share them with the world, you Push(upload).

Pulling code

If a teammate makes changes to the code on GitHub, your local computer won't know about it automatically. You need to pull those changes down(refresh or sync).

Essentials Commands Cheat Sheet

Action Command
Initialize git init
Check Status git status
Stage Changes git add <file>
Commit git commit -m "message
Push git push origin main
Pull git pull origin main

Top comments (1)

Collapse
 
shashwathsh profile image
Shashwath S H

To commit all files, use "git add ."

I usually use IntelliJ IDEA, because we do not need to write those git commands, there are direct commit and push options
IntelliJ IDEA

Try to use this IDE for your ease