A Guide to Git & Github

Aakash Verma
5 min readJun 30, 2020

--

Make your Developer workflow better with VCS’s

What’s a Version Control System ?

A version control system or VCS, tracks the history of changes made to a document as developers and teams collaborate on project together . As the project evolves, teams can run tests, contribute new codes, change previously committed code, fix bugs with the confidence that any version can be recovered at any time .

Project history can be reviewed to find out :-

> which changes were made ?

> who made the changes ?

>Why were changes needed ?

What is Git ?

So, Git is a distributed version-control system for tracking changes made in source code during software development. It is designed for coordinating work among programmers but it can be used for tracking changes made to any files .

The Three States in Git :

Git has three main states that your files can reside in : Modified, Staged and Committed :

Modified means that you made changes to the files but did not committed to the database yet .

Staged means that you have marked a modified file in its current version to go into your next commit snapshot .

Commited means that data is safely saved in your local database.

The basic Git workflow goes something like this :-

> You modify files in your working Tree.

> You selectively stage just those changes you want to be a part of your next commit , which adds only changes to the staging area.

> You do a commit , which takes the files as they are in the staging area and stores that snapshot permanently to your git Directory .

If a particular version of a file is in the Git directory, it’s considered committed. If it has been modified and was added to the staging area, it is staged. And if it was changed since it was checked out but has not been staged, it is modified

There are a lot of different ways to use Git. There are the original command-line tools, and there are many graphical user interfaces also . it depends on Us to use whichever we like . But The command line is the only place where you can run all Git commands — most of the GUI’s implement only a partial subset of Git Functionality for simplicity.

You can download git According to your OS using this LINK

Basic Git commands : —

To use Git, developers use specific commands to copy, create, change, and combine code. These commands can be executed directly from the command line or by using an application like GitHub Desktop or Git Kraken. Here are some common commands for using Git:

  • git init initializes a brand new Git repository and begins tracking an existing directory.
  • git clone creates a local copy of a project that already exists remotely. The clone includes all the project’s files, history, and branches.
  • git add stages a change. This command performs staging, the first part of that two-step process. Any changes that are staged will become a part of the next snapshot and a part of the project’s history.
  • git commit saves the snapshot to the project history and completes the change-tracking process. Anything that’s been staged with git add will become a part of the snapshot with git commit.
  • git status shows the status of changes as untracked, modified, or staged.
  • git branch shows the branches being worked on locally.
  • git merge merges lines of development together. This command is typically used to combine changes made on two distinct branches. For example, a developer would merge when they want to combine changes from a feature branch into the master branch for deployment.
  • git pull updates the local line of development with updates from its remote counterpart. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.
  • git push updates the remote repository with any commits made locally to a branch

For Full reference to list of git commands Follow the link

How Github Works ?

Github is Git a Git respository that provides with tools to provide better code through command line features , issues, pull requests, code review, or use apps in Github market place. Gitthub buils collaboration directly into the development process. Work is organized into repositories, where developers simply create a branch to work on updates, commit changes to save them, open a pull request to propose and discuss changes, and merge pull requests once everyone agrees with the code .

The Github Flow:-

Github flow has six basic steps , each with distinct benefits when implemented : —

  1. Create a branch: Branches created from the canonical deployment branch (usually master) allow teams to contribute to many parallel efforts.
  2. Add commits: Snapshots of Changes made within a branch create safe, revertible points in the project’s history.
  3. Open a pull request: Pull requests publicize a project’s ongoing efforts and set the tone for a transparent development process.
  4. Discuss and review code: Teams participate in code reviews by commenting, testing, and reviewing open pull requests .
  5. Merge: Upon clicking merge, GitHub automatically performs the equivalent of a local ‘git merge’ operation.
  6. Deploy: Teams can choose the best release cycles or incorporate continuous integration tools and operate with the assurance that code on the deployment branch has gone through a robust workflow.

Example : Start a new repository and publish it to GitHub

# initialize the folder with git repository
git init the-repo

# cd into the `the-repo` directory
cd the-repo

# create the first file in the project
#Open in text editor and add new file and edit it , for example file1.txt, #file2.txt.

# stage added files
git add file1.txt file2.txt

# take a snapshot of the staging area
git commit -m "initial commit"

# provide the path for the repository you created on github
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git

# push changes to github
git push --set-upstream origin master

Example : Contribute code to existing respository

#Create a git respository from your github account 
git clone link of that repository
# change into the `repo` directory
cd repo

# create a new branch to store any new changes
git branch my-branch

# switch to that branch
git checkout my-branch

# make changes to the files using the text editor

# stage the changed files
git add (Name of files or folders to be staged )

# take a snapshot of the staging area
git commit -m "my snapshot"

# push changes to github
git push --set-upstream origin my-branch

That’s It. These are the basic github workflow and examples. Hope its’ clear to you how git and github works .If you want to learn more about Git and Github please go through this links. Do comment and let me know how Useful git is to You . Clap if you find it informative .

--

--

Aakash Verma

Computer Science Undergrad ,Tech Enthusiast , Loves writing about Technology