DEV Community

Hellen A.
Hellen A.

Posted on

A Beginner's Workflow to Git

Hearing Git and Github for the first time may seem confusing but let me simplify the basics for you.
Think of Git as the vehicle that lets you keep a diary of your work. GitHub is just one destination you can drive to if you want to share that diary with others.

Git and Github diagram

According to Wikipedia, Git is a distributed version control software system that is capable of managing versions of source code or data. Github on the other hand is a proprietary developer platform that allows developers to create, store, manage, and share their code.

When using Git and Github as a beginner, there are key things to understand. First of all, there are 4 locations that we should mention.

  1. Working Directory
  2. Staging Area
  3. Local Repository
  4. Remote Repository

Let's go over them as we dissect over the commands we need to use.

1. Working Directory

This is the place in your local machine where your code is stored. To move your code from here we use,

git add .

The dot (.) means 'this directory'. The command adds all the code in the current directory to the staging area.

2. Staging Area

This contains the data that has been added from your working directory. To move to the next stage, we take a snapshot of this data. While doing this, we add a message that defines what the changes in the code are about.

git commit -m 'message'

3. Local Repository

This area contains the snapshot of the code. Before pushing for the first time, you need to tell Git where your remote repository is. You do this once with,

git remote add origin <url>

From here we use the below command to the next location.
git push

4. Remote Repository

This is where the pushed code stays.

The diagram below represents the workflow.
The flow diagram of the 4 Areas

You can also pull your data from the Remote Repository to your Working directory. You use the below command,

git pull

This command puts together 2 commands: git fetch and git merge. The former gets the data while the latter merges it with what is in your working directory.

As the diagram below shows, git pull is really fetch + mergecombined
Git Pull, includes fetch and merge

The next time you work with Git, I hope you are able to understand more clearly the next steps and environment that you are in.

P.S. Git isn't the only version control system out there, and GitHub isn't the only place to host your code, alternatives include Mercurial, Subversion (SVN), and Perforce for version control, and GitLab, Bitbucket, and SourceForge for hosting.

Happy Learning!

Top comments (0)