Wednesday, December 11, 2013

StartUp with GIT (Source Code Management)

What is GIT
Git /ɡɪt/ is a software for the distributed revision control and source code management (SCM) system.

Why GIT
Every Git working directory is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server.

GIT vs SVN
Subversion allows you to check out just a subtree of a repository; Git requires you to clone the entire repository (including history) and create a working copy that mirrors at least a subset of the items under version control.

Why GIT is named as GIT
Random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant.


Where to find GIT
You can download GIT from the http://git-scm.com/downloads

StartUp with GIT
There are also other graphical UI tools available for GIT which make easy in use, although I prefer the Git Bash with command line.
There is no exact way of using the Git. You can use it in your own way. It just keeps track of modification of your code for which any revision can be performed at any time.

Athough lets go to simple steps for
Creating New Local Git Reopsitory

  1. First of all, go to the project working directory via bash command line. eg. cd
  2. Initialize the repository by typing "git init". The ".git" folder appear in the directory with hidden properties.
  3. Now add all the existing file in the repo for versioning by typing "git add ." (add all files)
  4. Tell that you have comitted the changes and record it with the message by typing "git commit -am ".
  5. You have to set the name and email before comitting changes if it is not configured or if it shows error in step 4 while comitting. Type "git config user.name " and "git config user.email your@email"
  6. Your local repository is ready. Now you can code safely. And DON'T forget to comit for each changes in your coding logic. You can revise each of them later on at any time.

Creating Online Repository

  1. You can easily create account in http://github.com . After logging in, click on "Create Repository", provide name and other details of repo and submit it.
  2. You will find a online link of your repository in the page. Copy the link.
  3. Now go to the local repo you have created earlier and type "git remote set-url origin "
  4. Next pull the data from the remote repo by "git pull origin master". (Username and password is promped at this time)
  5. Again push your data to the server by "git push origin master". (username and password is promped)
  6. Now you can see your data in your github repo.

Cloning Repository
You can easily clone any public project you see in github.com by typing "git clone ". github url is provided in every project page or you can copy the addressbar url directly.

Other Ways
There are plenty of ways and lots of commands for using GIT.
You can clone, fork, make branches, revert, checkout, stash, set tags, view logs, etc.
You can get lots of other help and the way for using git. Although you can use GIT in your on way.

Some useful GIT commands

  • git init => Initialing new repo
  • git clone <git_url> => Cloning 
  • git remote add origin https://hereshem@github.com/...  => set the origin url for first time
  • git remote set-url origin https://hereshem@... => change the origin url
  • git config user.name "Hem Shrestha" => set name identity in the repo
  • git config user.email "hereshem@gmail.com" => set email identity in repo
  • git branch -a -l  => view all available branches
  • git checkout <branch_name> => switch to the branch
  • git status => view changes in source after last commit
  • git add .  => add all the untracked file
  • git commit -am "message" => commit changes in repo
  • git pull origin master => pull changes from remote
  • git push origin master => push changes to remote


For Server side GIT (Creating bare repository and set the folder and user permissions)

  • git init --bare
  • sudo chmod -R g+ws *
  • sudo chgrp -R mygroup *
  • git repo-config core.sharedRepository true


Happy Coding!.. ;)

No comments:

Post a Comment