Pages

Git simplified and master it in 10 minutes!

OK, what is this Git thing! Just because the developers use it, doesn't mean its rocket science.
Some are using it to work on family photo albums so it should be useful for all.

Imagine if you were composing a document and wanted a far off friend's help on it, you would write the initial draft, then email the attachment to your friend, he would download, save a copy, edit it and then email it to you.
Now suppose instead of this emailing overhead, if we could just have this document stored on your computer and your final edits pushed and stored on a web repository which your friend can download from and work on it locally and push the changes to the web repo until its perfect.

Different versions of this document from the initial one to the final one is stored and available and could be called Versions, since the docs are available with everyone working on it and not central its distributed and you and your friend have a set of rules to control the flow, combing it, distributed version control system (DVCS).
The reason for its increased adaptation is 1. No central repo so no point of failure. 2. Open Source

Ok going right into the crux.

Any time you need help on something, and to also check if git it already installed, launch a terminal and type the below, if git is not installed, just google for how to install it on your machine.

  • git help

Just adding our details on Git now so that it know who we are and changes to a doc could be accredited to us


  • git config --global user.name "Venu Murthy"
  • git config --global user.email "xyz@xyz.com" 

Once that is done, lets now go into a directory that you would like to put on Git. mkdir testgit, change to that directory by typing cd testgit


  • git init
Output is "Initialized empty Git repository in /Users/venum/testgit/.git/"

Once you initialised the git, we can check the status of what files have been added or modified by 
  • git status
The workflow is

File created or modified ====staged==> Ready for Save ======commit====> Saved on Repo on disk

So now we need to stage the file i.e. similar to save the modifications to the file on our harddisk. 
  • git add <filename>
filename could be the file name or a wildcard like *.txt or --all to checkin all files in the directory.

once this has been done, we now need to launch the staged file to the repo, its called commit. 
  • git commit -m "some comment--keep it in present tense"
to see the history of what has been done so far
  • git log


To see the changes or differences that have happened after the last commit of a file
  • git diff <filename>
So far we've been able to add files to our repo on disk, now lets push our local "master" to Git source control so that it can be shared. Register on Github.com for eg. Once you create a repo below is how you tell your git on where to push these files
  • git remote add origin https://github.com/venumurthy/testgit.git
  • git push -u origin master
in the above command -u is so that it remembers the parameters so that we wouldn't have to give it the next time. Origin is destination to which master is going to be copied to. 

Go to github and check if your files have come in. After this when you make any changes to the file, remember to do the following:-

  • git add <filename>
  • git commit -m "some comment"
  • git push

Congratulate yourself now for having tamed the octocat!