Git Tutorial

What is Git?
Git is open source Distributed Version Control System. Git  plays an important role when collaborating on project by team members located  geographically at different locations.

Local repository vs Remote Repository
  • Create a directory where you would like to create local repository and fire command $git init to create local repository
  • When you would like to collaborate with team which work on the same project and would like to contribute to it then create remote repository (e.g. GitHub).


When we work with local repository there are there places where our files stay during its life-cycle in git.
1. Working Directory- Untracked and modified files are kept here. These files can be listed using $git status command
2. Staging Area - a cache of files that you want to commit
3. Local Repository- Directory with name .git in working directory.


(Image source- https://softwareengineering.stackexchange.com/questions/119782/what-does-stage-mean-in-git)

Setting configuration variables
$git config --global user.name <user name>
$git config --global user.mail <email_id>
To list configuration parameters
$git config --list

Important commands of git
  • List the files you've changed and those you still need to add or commit: $git status
  • Adding a file in git staging area- $git add <name_of_file>
  • Un-staging a file from git staging area- $git reset <name_of_file>
  • Committing file from git staging area to repository- $git commit -m <message>
  • To show commit history- $git log
  • View all the merge conflicts- $git diff
  • Checking difference from last commit- $git diff HEAD
  • HEAD points to recent commit
  • Branching out from master $git branch <name_of_branch>
  • switching branches $git checkout <branch>
  • to merge branch with master $git merge <name of branch>
  • Deleting a branch $git branch -d <branch name>
Remote repository:
  • Cloning remote repository -  $git clone https://github.com/DJP/myproject myProject
  • Viewing information about remote repository- $git remote -v
  • Push all branches to your remote repository:- $git push origin master
  • Fetch and merge changes on the remote server to your working directory- $git pull origin master
Git common work-flow diagram-




(Image Source- https://wiki.lsr.ei.tum.de/lib/exe/fetch.php?media=nst/programming/git_flow.jpg&w=500&tok=e87798)

Why is git useful?
Large software projects require some piece of software to keep track of all the different changes made to a code base in order to track things like:  Who edited a certain file; what they changed; and how to get back to the original code if necessary.  Git does all of these things and more, so it's not surprising that most large software companies use git!

References:
1.https://try.github.io
2.https://www.youtube.com/watch?v=HVsySz-h9r4
3.https://stackoverflow.com/questions/13072111/gits-local-repository-and-remote-repository-confusing-concepts
4.http://rogerdudler.github.io/git-guide/
5.http://blog.robertelder.org/what-is-git/

Comments

Popular posts from this blog

Three Screen App Idea

Week 8 - Final App

Setup dev environment