DEV Community

Cover image for G for Git
Sumit Roy
Sumit Roy

Posted on • Updated on

G for Git

What is git?

Git is a distributed version control system which helps developers to collaborate globally.

Why we need such version control system?

Well we need version control system for the following reasons:-

  • It keeps the history of changes developers made.
  • We know who made what changes.
  • It merges conflicting changes (such as two people modified a single file at the same time then it will merge both the changes).

Workflow that makes your project flow smoothly

There are 3 workflows that you can go within Github, namely:-

  • Centralized Workflow

    It is used generally for small teams where everyone works on single branch in a central repository

  • Feature Branch Workflow

    Features developed in dedicated branches and then merged with the main codebase using pull request. Here the main codebase is kept clean and working

  • Forking Workflow

    Each developer forks from the main repo and do changes and send pull requests. Here each developer will have own online repo of the project

Since this a small project right now I will start with centralized workflow.

Enough theory let's do some practical

As hasura provides git integration in their platform I am going to use GitHub as my code repository. So let's initialise our codebase. For instructions about installing git on your computer go to this link. First I have to create a folder and type the command

git init

This will initialise my codebase and track my changes. You will see a hidden folder is created inside my folder snipcode named .git. It contains all the files required for version control.

After adding a readme file to commit the following changes in snip code we have to add and it to the staging area and then commit.

git add
git commit -m "Initial commit"

git commit has an option of adding a message to the commit.

Now all these are happening in my local environment. To push my codebase in GitHub I have to create a repo named snipcode.

After this, I will add the remote in my local repo with name origin(general convention).

git remote add origin

Finally, I will push my local repo to GitHub using push command in the master branch

git push origin master

One of the useful commands is git status. We should always use this to know the status of working tree. One snapshot of my project's status is

And here is the cheat sheet for git provided by the Tower.

Here is the index of all the post regarding this series of snipcode developemnt

Part I: App Idea
Part II: App prototype
Part III: Local Development
Part IV: G for Git
Part V: Data Modeling
Part VI: Data & Auth APIs
Part VII: Basic Functionalities
Part VIII: App Screen 1
Part IX: App Screen 2
Part X: App Screen 3
Part XI: User Reviews
Part X: Final Submission

Liked my post?

Top comments (4)

engineercoding profile image
Wesley Ameling

Thanks for this! I will refer people to this article when they need to learn the basics of git, instead of my own (messy) notes.

sroy8091 profile image
Sumit Roy

Sure. They can directly ask questions to me also. I will try my best.

mjcoder profile image
Mohammad Javed

Thanks - will use this as a reference :-)

petecapecod profile image
Peter Cruckshank

Great article, I like how you broke it down into short sections. Makes it easier to follow. Love the cheatsheet too