Of late I was working with my buddies on some open source projects hosted in GitHub. In my continuous journey I was learning some basic Shell commands through which Git management can be easily accomplished. In this short tutorial, I am going to narrate on how to do simple Git operations through Git Shell. As a prerequisite download and install GitHub tools for Windows – http://windows.github.com/. In case if you are finding problems with Git Shell, check out this StackOverflow question.
=======================================================================================================
Create Repository
=======================================================================================================
Logon to GitHub account and navigate to Repositories tab. Click on New.

Enter relevant details and click Create Repository.

Once repository created, we will land up with following summary.

=======================================================================================================
Clone Repository
=======================================================================================================
Open Git Shell for Windows by clicking below icon (which should be coming along with GitHub tools for Windows installation).

It will open PowerShell console and by default point to the local location where GitHub has been pointed too (Unfortunately I forgot on how I configured that location at the time of installation, from my sub-conscious memory I remember it is pretty straight forward).

Now we need to get GitHub Clone URL. Check out below screen shot.

Now execute the following command.

Once cloning has been done, we can get into the Master branch of the Repository.

Local GitHub repository can also be navigated through windows explorer.

=======================================================================================================
Create a Branch
=======================================================================================================
It is always a good practice to create a branch of master and work on it. One should have a healthy Master copy to make replicas of branches, so that different people will work on different releases, features and bugs.
Use following commands to create a branch locally, then push it to GitHub and finally change the context of shell from Master to created branch.

With above steps you can check our newly created branch in GitHub portal.

=======================================================================================================
Commit to a Branch
=======================================================================================================
now we can go ahead and make changes to the repository files in local. For simplicity, I am going to add Test.txt (a sample text file) and edit README file. Save changes in local.

Now make a Git Status call.

Add the changes to present context.

Commit the changes.

Finally push the changes to GitHub Repository.

NOTE: Origin is created at the first time cloning of the repository. It creates a path to commit and push changes to online GitHub Repository from ta local cloned repository.
We can check online GitHub repository now to check whether our changes are available or not.

=======================================================================================================
Fetch latest from a Branch
=======================================================================================================
To demonstrate fetch concept, let us update Test.txt file in the GitHub Portal. Click the Test.txt file and there by it can be edited using Edit option at the top and then finally commit changes to the file.

To get this change to our local, we can execute following commands.

And now if we go and check the local repository text file, changes will be reflected.

=======================================================================================================
Merge Branch with Master
=======================================================================================================
As a final step of this tutorial, we are going to merge the branch version to our Master version. First we make sure we get the branch version up to date in our local.

Then merge the changes to Master.

We can cross check the updated master version in the GitHub portal.

This completed our first getting started tutorial for GitHub. In next set of tutorials, we are going to work with Forking of repositories, Merging with remote repositories and more complicated merge scenarios.
Happy Coding!!!






Pingback: TechNet Blogs()