Creating your first commit

We have created our first repository on GitHub. It resides on cloud/server of GitHub.
But mostly as a developer we carry out our code development on our local PC.
So we need one interface with GitHub so that we can get/send code from/to GitHub using commands.

Installing Git command line client

I am using Virtual Machine that runs Ubuntu so I will be installing Git clied o Ubuntu terminal using following command

sudo apt-get install git

Once installed successfully configure your git with your Git account details (email, Git username).

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

After this you are ready to use GitHub from your local PC.


Getting existing repository to your local machine

Since we have created our repository on GitHub Server we will fetch the repository contents to our local PC using following command.

git clone <Your Repository Link>

e.g.
git clone https://github.com/embeltech/test.git

You can find your repo link as follows:
Go to link https://github.com/Username/YourRepoName
e.g. https://github.com/embeltech/test
Click on code button and copy HTTPS link (your repo link).



Once git clone is complete you can navigate to the downloaded folder of repository and check its contents.


You have successfully created local copy of your repository

Add new code to the repository

Once local copy of repository is available on your local machine we can now create one hello world cpp program or you can create any document or even copy any existing file to the repository folder.

After we have new document added to our repository git detects new items as untracked/unstaged items (More on this in next article).

Check status of your changes:

git status


Staging

Git is a version controlling system (VCS) so we want git to to maintain versions of the file that we added. In order to make git to track the code changes we need to add the file to staging area  (More on this in next article). Use following command to add file to staging:

git add fileName

e.g. git add hello.cpp


Check the status using git status
New file is now staged for next step (commit)

Committing

After staging(making git aware of our changes so that they will be tracked) now we need to make git register the changes in its version database. So we commit the changes.

git commit -m  "Your commit message here"


Check the status using git status
New file is now committed into version database

Pushing

All the process that we have done is on local copy of the repository. Even version history captured in its database is also local and present in your machine only.
In order to send the changes to GitHub server repository we need to push the changes to server.

git push


Check the status using git status.

You have successfully created first commit to your GitHub (SERVER) repository.
Have a look from GitHub website.


Your commit has been identified with a unique SHA (Secure Hash Key)

Congratulations on your First Commit !!!

Creating your first GitHub repository


After creating and sign in Github account its time to create your own source code repository.
First we will start with creation of blank repository and then we will push some code into the created repository (repo in short)

Create Blank Repo:

After you sign in you will be presented with the landing page of Github where you can start creating your repositories. Hit Create repository button and follow the instructions.




Create your repository with following details.
  • Repository name : Name of your source code module/ application/ project or as per your wish.
  • Description: This section can be used to describe your source code or project in short
  • Choose whether the source code is visible to all or its private
  • Initialize Repo with read me file, gitignore file, license file (If you are not sure about license and ignore files then leave unselected)
  • Default branch name will be main but you can change it by clicking settings link. (Its common practice to keep it as master)
  • Hit Create repository button


Congratulations !! You have created your own first Github repo.



Manage access:

If you are planning to use the repository by yourself then there is no need to do this step.
But if you are planning to share this repository with your friends/teammates so that they can edit/change the source code then invite collaborators.
Go to Repo Settings >> Manage Access >> Hit Invite a collaborator button.




Add GitHub usernames/email of your friends/teammates to grant them collaborator access.

Delete Repo:

In case if you want to delete the repository then go to Repo Settings >> Options >> scroll down to  Danger Zone and hit Delete this repository button.





Getting started with GitHub


Why GitHub? 

There are several Git repositories that offer git VCS but GitHub is most popular and widely used repository.
It is free and used by million developers including Linus Torvalds (The creator of Linux)
Many organizations use GitHub.





Many popular code repositories are hosted on GitHub:

The source code of Linux kernel is hosted on GitHub by Linus Torvalds himself.

Source code of git itself can be found on GitHub:

Sign Up

First step to become part of 50M+ developers' GitHub community is to signup and then sign in

Note: username & password are important to use repositories from command line/client PC

  

What is Git

A Short History of Git

The Linux kernel is an open source software project of fairly large size. 
For most of the time of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files. 
In 2002, the Linux kernel project began using a proprietary Distributed VCS called BitKeeper.

In 2005, the relationship between the Linux community  and BitKeeper developers broke down, and the tool’s free-of-charge status was revoked.
This inspired Linux community (in particular Linus Torvalds, the creator of Linux) to develop their own framework of VCS  based on some of the lessons they learned while using BitKeeper. 

Since its birth in 2005, Git has evolved and matured to be easy to use.

Git implementations

Git is open source (free) version control system.
  • Git under Windows(Mingw-w64, Cygwin).
  • The JGit implementation of Git is a pure Java software library.
  • go-git is an open-source implementation of Git written in pure Go.
  • The Dulwich implementation of Git is a pure Python.
  • The libgit2 implementation of Git is an ANSI C software library with no other dependencies, which can be built on multiple platforms, including Windows, Linux, macOS, and BSD.
  • JS-Git is a JavaScript implementation of a subset of Git.

Git server as a service

There are many offerings of Git repositories as a service. The most popular are
  • GitHub
  • SourceForge
  • Bitbucket
  • GitLab
Git Repository services are like storages that host your source code with git VCS.

Official Git website:

Git Source code management

Git Full form In case you wonder...

The name "git" was given by Linus Torvalds when he wrote the very first version. He described the tool as "the stupid content tracker" and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • "goddamn idiotic truckload of sh*t": when it breaks
Reference: Git Readme

Version Control System

Simplest way to backup your source code is to store all files on your local machine's hard drive.
But this way has its own set of problems.

Problem#1 : Hard disk failure/ Accidental deletion of code/ Corrupted source code files

Code might get lost if some one accidently deletes the files or files get corrupted due to some unknown reasons.
 

Problem#2 : Multiple developers cannot work on same source code files easily.

If multiple developers working on same project or even same files then its very difficult to keep track of all their code changes and integration of such modified code is another challenge.



Problem#3 : Reverting back to older version of source code files is not easy.

If developer made some changes in source code and while testing it is found that software is failing then very quick solution is to revert/undo all changes and shift to older working version of source code.
Older version is not available since developer modified the existing copy so in such scenario its not practical to undo changes manually.    



Solution on all such problems is Version Control System (VCS).

Solution#1 : 

VCS software run on secure servers and hence maintain source code on cloud. I case of any code lost scenario (file deletion/ hard disk failure/ file corruption) the source code can be restored by copying it from servers to local machine.



Solution#2 :

VCS has software framework that maintains code versions and has tools/mechanism to merge code from all developers working on same source code from different local machines. Code integration problems will get resolved due to VCS.


Solution#3:

VCS has software frame work that maintains version history so reverting back to older working version of source code is very easy.
 



Version Control Systems examples: