Friday, 23 August 2013

Git Hub Tutorial. Introduction to commands.

Introduction: 
When working on a project, you need to manage and organize the code. 
Like organize according to User modified a file in the project, or Date and time when you changed the file and many other.
Git keep the track of the files you changed and also allow you to update the code on remote device,and allow your team mates to access the code. Now, they can access the modify code and all other files in more organized way. 
Difference:
The major difference between Git and any other VCS (Subversion and friends included) is the way Git thinks about its data. Conceptually, most other systems store information as a list of file-based changes. These systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they keep as a set of files and the changes made to each file over time.

Git doesn’t think of or store its data this way. Instead, Git thinks of its data more like "SAVED STATE", a set of snapshots of a mini filesystem. Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
For Example if a major Bug occurs after the changes then you can go back to a "saved state", start building again from there. Like that you paused a game to a state and then can resume from that point.
To be efficient, if files have not changed, Git doesn’t store the file again—just a link to the previous identical file it has already stored.
      pull 
  <---------------------
    User                                        Remote Repository        
      -----------------------> 
                     push

pull    -   Fetch data from Remote Repository.
push  -   Update the Remote Repository with local changes.


USER 1 USER2
        \ \         / /
          \  \     / /
       Remote Repository        
            / /     \ \                                            
              / /           \ \
        USER n USER3






There are two easy ways to install Git on a Mac. The easiest is to use the graphical Git installer, which you can download from the Google Code page 
http://code.google.com/p/git-osx-installer
The other major way is to install Git via MacPorts (http://www.macports.org). 
If you have MacPorts installed, install Git via
$ sudo port install git-core +svn +doc +bash_completion +gitweb
You don’t have to add all the extras, but you’ll probably want to include +svn in case you ever have to use Git with Subversion repositories



Lets Begin:
Press "cmd" + space"
Type : "terminal" in spotlight.
It will open a terminal window. 

Browse to folder where you want to store the project locally. You can "cd" command to navigate in in your folders.
cd Users/HD/Desktop/Git/
It will take to the folder Git.

You clone a repository with git clone [url]. For example, if you want to clone the Ruby Git library called Grit, you can do so like this:
$ git clone git://github.com/HD/grit.git


The main tool you use to determine which files are in which state is the git status command. If you run this command directly after a clone, you should see something like this:
$ git status


In order to begin tracking a new file, you use the command git add. To begin tracking the READMEfile, you can run this:
$ git add README

Now that your staging area is set up the way you want it, you can commit your changes. Remember that anything that is still unstaged — any files you have created or modified that you haven’t rungit add on since you edited them — won’t go into this commit. They will stay as modified files on your disk. In this case, the last time you ran git status, you saw that everything was staged, so you’re ready to commit your changes. The simplest way to commit is to type git commit:
You can type your commit message inline with the commit command by specifying it after a -m flag, like this:
$ git commit -m "Eg: This is custom msg related to commit"




Pushing Remotely
The push command tells Git where to put our commits when we're ready, and boy we're ready. So let's push our local changes to our origin repo (on GitHub).
The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it! 
$ git push -u origin master





eBook:
Tuts:

No comments:

Post a Comment