Contact Us

Get Git go Github

Part-1 Get going with Git

This workshop on Git and Github is written with a very simple goal in mind and it is to help programmers start using Git and Github. Following are some of the questions and statements which have always hindered use of Git and Github by programmers.
  1. I don't understand it, why should I use it ?
  2. I am an individual not working with teams, why should I use it ?
  3. I am not comfortable with it, I'll use it later in life
  4. My code is not good enough to be public
Well if any of these questions or statements are stopping you from using Git and Github then it is the right time to overcome these not only because latter are great tools but because of many other reasons like:
  1. They are more easier to start with than you ever thought, this workshop will prove it
  2. Many companies will look at your Github profile before hiring you as a programmer
  3. You can not best judge your code, you never know who may find your code to be very useful
  4. If you don't publish your code, it dies inside of your laptop only
OK, enough of motivation. Now let's come to real business. This workshop is divided into 2 parts, First introduces Git and Github and then helps you to start with Git. The second part of this workshop talks about Github a place which is a home for millions of lines of great code.
Introduction to Git.
Git is a free VCS [Version Control System]. In simplest of terms it helps you manage your code. In case of writing a hello world program it may sound less obvious to use Git but when things get large and messy, Git is your rescue boat. One of the examples can be a Mobile App project, where you've to release a different version of the app every week and you also have to keep all the previous app versions so you can get back to it in case of a flaw in the newer version. We can of course do a lot of copy paste and juggle our heads into remembering where each and every file is or we can simply let Git handle this for us because this is what Git is good at among other things.
In the world of Git Code lives inside a special entity called a Git repository or repo for short. And we have a special Git software which helps us in following ::
  1. Creating a Repo
  2. Adding code to it
  3. Committing code to it when all additions are done
  4. pushing code to an identical remote repo for others to access or to simply keep track of it in case of failure or accidental delete on local machine.
Download Git
To start using Git, you need the git software tools bundle which you can download from following official link:
Download Git
After you've installed GIT, you're ready to create your first repo. If you're using linux you can type the following commands directly in shell, but in case of windows you can click the windows icon at bottom left and search for git-bash which opens a terminal where you can type your commands.
Create a GIT Repo

$ cd directory_of_your_choice
$ git init
Initialized empty Git repository in c:/directory_of_your_choice 
Add Code to your Repo
In your git bash, type only the code that starts with '$' sign, all other lines show output.

$ echo "your_name" >> authors.txt
$ git status
On branch master
Initial commit
Untracked files:
  (use "git add ..." to include in what will be committed)
nothing added to commit but untracked files present (use "git add" to track)
$ git add authors.txt
$ git status
On branch master
Initial commit
Changes to be committed:
  (use "git rm --cached ..." to unstage)
        new file:   contributors.txt

In a similar fashion you can add more files to your git repo and you can also change the files you have added before using your favourite IDE or code editor. Just remember to keep adding your files to your git repo each time using git add -A

Note that git add -A adds all the files to repo at once

Commit your code to the repo
Once you've edited the necessary files and you want to keep these changes. It's time to commit this code to your git repo. Note that when you commit code to repo, It is available for as long as the repo exists. So you should commit you code regularly at different milestones of your peojct just in case you want to jump back. Following code snippet shows how to commit code to repo.

$ git commit -m 'my first commit to repo' 
 1 file changed, 1 insertion(+)
 create mode 100644 contributors.txt
$ git status
On branch master
nothing to commit, working directory clean
Your code is ready for a push
Once we have a useful piece of code, we may really want to make it available for other to use. It means that we need some space online where we can keep an exact copy of the repo we created so that others can access it. There are many platforms which provide us free space to host our code. Notable examples are GITHUB and BITBUCKET . We'll be creating a remote repo on github and push our code to that repo in next part of this tutorial.

developed & nourished with by rishabh.io