Tutorials‎ > ‎

Git




Before you begin:

    1. You already should know about version control systems & repositories, heard about things  like commit, merge, conflict, stage, branches & revert.
    2. you will learn about distributed version control & know about origin, master, push, pull, clone, init.
    3. you will relearn what add, commit and other differences.

Git is a distributed version control system where files reside at both local and remote. Your copy is called the working tree and the central server is called the bare repository.

once the cloning is done, your local copy is called a local repository since anybody can treat your local copy as a repository itself and do everything on it which is expected from a remote centralized repository. that's why Git is a DVCS not just a simple VCS.

you start by "cloning" the remote repository to your local environment.

From the local copy's perspective , the remote by default is called "origin".

by default, a local branch called "master" is created which is linked to the "master" branch at the "origin". if there are any other branches at the remote , all those are locally cloned too.

so you have local branches and remote branches and your local branch is called tracking branch and the remote is called tracked branch.

you change the files in your local copy(cloned  copy or the working tree) and "commit" them.

before committing , you may need to "add" the new files into the local repository. noe the files are in the staged or indexed state.

any local file will initially be in the working directory and then by issuing "add" command will move into staged or indexed state and then by issuing "commit" command will move into committed state or is written into the Git history

after committing, if you want to store the files at remote then you need to do a "push".

similarly you do a "pull" to get the latest files from the remote to your local which automatically do a  "merge" or "rebase" those new changes into your local repo.

instead of "pull", if you do a "fetch", you will manually need to do a "merge".

if you are the one who is creating the repo for the first time, then you need to initialize the local working directory with a "init", then "add" , then "commit" and then finally "push".

working with branches in git involves "push", "pull", "merge" & "rebase" on one end and "branch" and "checkout" on the other end.

"push" commits changes to the remote repo from your local repo.

"pull" brings in changes from remote repo into your local and has not yet merged it.

"merge" will blend in the changes from one branch to other. the branch may be remote or local.

"rebase" will also do a merge but instead of blending in the changes at the point of branch creation, the blending happens at the point of the latest version of the parent branch. i.e. if there are not conflicts. "rebase" is an easier "merge".

HEAD is a pointer which points to the current branch, when you move branches by using "checkout" or "branch", the HEAD pointer changes and starts pointing to the current branch. it is called a HEAD because it represents the starting point to any new "commit"

the current branch is also a pointer which points to the latest commit. every branch has a HEAD

a "commit" in git is nothing but a recorded history with a reference or a pointer pointing to its parent commit. a commit is represented by a sha-id and is a pointer pointing to its parent. a commit always points to one previous commit or to 2 previous commits in case of merge, these are called merge commits.

refer:

http://marklodato.github.com/visual-git-guide/index-en.html

http://www.syntevo.com/smartgit/documentation.html




Comments