03/18/16 NOS Conf 2016 Version control system with git and (github) as an example Gaurav Garg @gaurav_garg_ ggarg@redhat.com freenode irc nic: ggarg
03/18/16 NOS Conf 2016 Agenda  VCS – What is it ?  Why using a VCS is good idea  Git Basic including: ➢How to obtain and install Git ➢How to use it for basic/common operation ➢More information resource for Git  Q & A
03/18/16 NOS Conf 2016 VCS What is it ? • A way to keep track of changes to files or folders • Keep record of changes why, what, when • Non distributed system (subversion, CVS) server has the master repo, all commit goes to the server • Distributed (Git, mercurial) server has the master repo, but you have copy of that repo (clone) in your machine
03/18/16 NOS Conf 2016 Getting Git •Dependencies: * on a system that has yum (such as fedora) $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel * on a system that has apt-get (debian based system) $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
03/18/16 NOS Conf 2016 Getting Git cont... •Get the latest snapshot from git website: http://git-scm.com/download Then, compile and install: $ tar -zxf git-1.7.2.2.tar.gz $ cd git-1.7.2.2 $ make prefix=/usr/local all $ sudo make prefix=/usr/local install
03/18/16 NOS Conf 2016 Getting Git cont... • Binary Installer: If you want to directly install binary then:  For Fedora: $ yum install git  For debina based distribution: $ apt-get install git  For mac $ brew install git
03/18/16 NOS Conf 2016 Git basic operation •Checking the installation: Check if Git is installed $ git - -version git version 1.9.3 If not then follow the installation steps that mentioned in previous slides. • Setting user name and email to your git config: $ git config --global user.name "Gaurav Kumar Garg" $ git config --global user.email " ggarg@redhat.com" Note: If you want to set it for specific repositery then cd to that repositery and Remove “--global” option. $ git config - -list command will verify user name and email address
03/18/16 NOS Conf 2016 Git basic operation cont... • Obtaining a repository: Creating a repository (if it does not exist remotely) $ git init (follow http://git-scm.com/docs/git-init for more information) Or cloning a remote repository: git clone ssh://[username@]git.gluster.org/glusterfs.git glusterfs For eg: cloning a gluserfs repository: git clone ssh://ggarg@git.gluster.org/glusterfs.git glusterfs here glusterfs is optional, which will be the name of repository. Inspecting a repo: $ vim .git/config
03/18/16 NOS Conf 2016 Git basic operation cont... • Inspecting repo: $ git tag will show you list of all tags (versioning of software) $ git status Difference b/w index file and current head commit $ git log Sow list of all commit with commit message $ git log -1 Show top 1st commit $ git log - -pretty=oneline Show list of all commit in single line
03/18/16 NOS Conf 2016 Git basic operation cont... • Making edit and commiting • Edit your file with your fav editor (vim/emac etc.) and save it. • $ git diff will show delta difference code of current master HEAD and current index • $ git status will show path of file as “Changes not staged for commit” • $ git add (-A) will show file as “Changes to be commited” • $ git commit -s write your commit message. Save and exit. * file changed, * insertion, * deletion (-) • Check your commit by $ git log
03/18/16 NOS Conf 2016 Git basic operation cont... • Recover your changes that you have added by mistakes $ git add <file name> file <file name> that you have added by mistake $ git status $ git reset HEAD <filename> $ git checkout - - <filename>
03/18/16 NOS Conf 2016 Git basic operation cont... • Best pratice is to make seperate branch $ git branch <branch name> or $ git checkout -b <branch name> $ git branch -D <branch name> will delete branch <branch name> $ git branch -m <branch name> <new name> will rename branch <branch name > with <new name>
03/18/16 NOS Conf 2016 Git basic operation cont... • Git Stashing Will allow you to save your changes without commiting them. • $ git stash save your change as a seperte stash@{*} branch with commit message • $ git stash list will show you list of all stash with commit message • $ git show <stash@{0}> will show you what code difference contain this this stash@{0} • $ git apply <stash@{0}> will allow to apply change in current branch.
03/18/16 NOS Conf 2016 Git basic operation cont... • Git rebase forward-port local commit to local upstream master • $ git rebase master * will update your local commit with master • $ git rebase -i HEAD~3 * will pick up top 3 commit and it * can be use for reword, edit, squash commit
03/18/16 NOS Conf 2016 Git basic operation cont... • Adding remote: • $ git remote add <remote name> <remote_url> Adding remote repo address in your local machine user can add multiple remote repo address • $ git remote -v will show you list of all remote address with name • $ git push <remote name> <branch name> will push <branch name> change to remote address
03/18/16 NOS Conf 2016 Git basic operation cont... • Git tagging • $ git tag * will list out all the tags (calles as versioning of software) • $ git tag -a <tag name> -m “tag description” * will give tag with tag name of tag version with current branch HEAD • $ git tag -d <tag name> * Delete tag <tag name>
03/18/16 NOS Conf 2016 More information resource for Git • $ git - -help for eg: git - -help <rebase> will give your help regarding “git rebase” • http://git-scm.com/docs/ contains resource of all git related command/operations.
03/18/16 NOS Conf 2016 Thank you....
03/18/16 NOS Conf 2016 Q/A

Version Control Systems with git (and github) as an example

  • 1.
    03/18/16 NOS Conf2016 Version control system with git and (github) as an example Gaurav Garg @gaurav_garg_ ggarg@redhat.com freenode irc nic: ggarg
  • 2.
    03/18/16 NOS Conf2016 Agenda  VCS – What is it ?  Why using a VCS is good idea  Git Basic including: ➢How to obtain and install Git ➢How to use it for basic/common operation ➢More information resource for Git  Q & A
  • 3.
    03/18/16 NOS Conf2016 VCS What is it ? • A way to keep track of changes to files or folders • Keep record of changes why, what, when • Non distributed system (subversion, CVS) server has the master repo, all commit goes to the server • Distributed (Git, mercurial) server has the master repo, but you have copy of that repo (clone) in your machine
  • 4.
    03/18/16 NOS Conf2016 Getting Git •Dependencies: * on a system that has yum (such as fedora) $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel * on a system that has apt-get (debian based system) $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
  • 5.
    03/18/16 NOS Conf2016 Getting Git cont... •Get the latest snapshot from git website: http://git-scm.com/download Then, compile and install: $ tar -zxf git-1.7.2.2.tar.gz $ cd git-1.7.2.2 $ make prefix=/usr/local all $ sudo make prefix=/usr/local install
  • 6.
    03/18/16 NOS Conf2016 Getting Git cont... • Binary Installer: If you want to directly install binary then:  For Fedora: $ yum install git  For debina based distribution: $ apt-get install git  For mac $ brew install git
  • 7.
    03/18/16 NOS Conf2016 Git basic operation •Checking the installation: Check if Git is installed $ git - -version git version 1.9.3 If not then follow the installation steps that mentioned in previous slides. • Setting user name and email to your git config: $ git config --global user.name "Gaurav Kumar Garg" $ git config --global user.email " ggarg@redhat.com" Note: If you want to set it for specific repositery then cd to that repositery and Remove “--global” option. $ git config - -list command will verify user name and email address
  • 8.
    03/18/16 NOS Conf2016 Git basic operation cont... • Obtaining a repository: Creating a repository (if it does not exist remotely) $ git init (follow http://git-scm.com/docs/git-init for more information) Or cloning a remote repository: git clone ssh://[username@]git.gluster.org/glusterfs.git glusterfs For eg: cloning a gluserfs repository: git clone ssh://ggarg@git.gluster.org/glusterfs.git glusterfs here glusterfs is optional, which will be the name of repository. Inspecting a repo: $ vim .git/config
  • 9.
    03/18/16 NOS Conf2016 Git basic operation cont... • Inspecting repo: $ git tag will show you list of all tags (versioning of software) $ git status Difference b/w index file and current head commit $ git log Sow list of all commit with commit message $ git log -1 Show top 1st commit $ git log - -pretty=oneline Show list of all commit in single line
  • 10.
    03/18/16 NOS Conf2016 Git basic operation cont... • Making edit and commiting • Edit your file with your fav editor (vim/emac etc.) and save it. • $ git diff will show delta difference code of current master HEAD and current index • $ git status will show path of file as “Changes not staged for commit” • $ git add (-A) will show file as “Changes to be commited” • $ git commit -s write your commit message. Save and exit. * file changed, * insertion, * deletion (-) • Check your commit by $ git log
  • 11.
    03/18/16 NOS Conf2016 Git basic operation cont... • Recover your changes that you have added by mistakes $ git add <file name> file <file name> that you have added by mistake $ git status $ git reset HEAD <filename> $ git checkout - - <filename>
  • 12.
    03/18/16 NOS Conf2016 Git basic operation cont... • Best pratice is to make seperate branch $ git branch <branch name> or $ git checkout -b <branch name> $ git branch -D <branch name> will delete branch <branch name> $ git branch -m <branch name> <new name> will rename branch <branch name > with <new name>
  • 13.
    03/18/16 NOS Conf2016 Git basic operation cont... • Git Stashing Will allow you to save your changes without commiting them. • $ git stash save your change as a seperte stash@{*} branch with commit message • $ git stash list will show you list of all stash with commit message • $ git show <stash@{0}> will show you what code difference contain this this stash@{0} • $ git apply <stash@{0}> will allow to apply change in current branch.
  • 14.
    03/18/16 NOS Conf2016 Git basic operation cont... • Git rebase forward-port local commit to local upstream master • $ git rebase master * will update your local commit with master • $ git rebase -i HEAD~3 * will pick up top 3 commit and it * can be use for reword, edit, squash commit
  • 15.
    03/18/16 NOS Conf2016 Git basic operation cont... • Adding remote: • $ git remote add <remote name> <remote_url> Adding remote repo address in your local machine user can add multiple remote repo address • $ git remote -v will show you list of all remote address with name • $ git push <remote name> <branch name> will push <branch name> change to remote address
  • 16.
    03/18/16 NOS Conf2016 Git basic operation cont... • Git tagging • $ git tag * will list out all the tags (calles as versioning of software) • $ git tag -a <tag name> -m “tag description” * will give tag with tag name of tag version with current branch HEAD • $ git tag -d <tag name> * Delete tag <tag name>
  • 17.
    03/18/16 NOS Conf2016 More information resource for Git • $ git - -help for eg: git - -help <rebase> will give your help regarding “git rebase” • http://git-scm.com/docs/ contains resource of all git related command/operations.
  • 18.
    03/18/16 NOS Conf2016 Thank you....
  • 19.