Git A Version Control System - by Amit Shrestha What is Git? • An open source, distributed version control system. • Started by Linus Torvalds. • Designed for the speed and efficiency. • allows a team of people to work together, all using the same files. • Can support thousands of parallel branches. How Git Manages Version? • Git Does not delete • Almost everything is local. Git Does Not Delete • Git generally adds data. • Works by taking snapshots of files • If unchanged in a particular version, simply links to the previous files. • Can recover the things if messed up. Almost Everything is Local • Generally no information is needed from the network. • Entire history of the project is locally stored on the local disk. How Git is different from other VCS? Other VCS: How is Git Different from other VCS? Git way of storage: Basic Git Workflow Basic Git Workflow • Modify files in your working directory. • Stage the files, adding snapshots of then to the staging area. • Do a commit, storing snapshot permanently to the git directory. Basic Git Setup • Install Git https://git-scm.com/book/en/v2/Getting-Started-Installing-Git • Configure Username and Email - git config --global user.name “name” - git config --global user.email “email_address” - git config --list Branching - Branching Branching - git checkout -b branch_name Branching - Edit whatever needed and do a commit - git commit -m “commit_message” Branching - Go back to master branch (git checkout master) - New Branch named hotfix. (git checkout -b hotfix) Branching - merge hotfix to the master branch - git merge hotfix Branching - continue with the previous branch. Branching - merge iss53 branch to master. - git merge iss53 Collaboration??? Github, a Remote Repository • A Hub where developers can store their projects and collaborate on them. • A graphical web interface for managing Git project • Each individual project has its own Repo. • Free for public projects (public repos). • Paid plans for the private repositories. 1. git init Git Basic Commands - creates a subdirectory named ‘.git’ 2. git clone “url” 3. git status - determines which files are in which state. 4. git add “file_name” OR git add . - stage or tracks the file. 5. git commit -m “message..” - write a descriptive commit message. Git Basic Commands 1. git log - lists the log of every commit made on that branch. 2. git stash - stores the changes temporarily. 3. git stash pop - retrieve the temporarily stored changes. 4. git checkout -b branch_name - create and switch to a new branch. Git Basic Commands 1. git merge branch_name - merge the given branch to the branch you are currently in. 2. git branch - lists all the branches. 3. git reset soft [commit] 4. git reset hard [commit] Other useful git commands 1. git diff 2. git log --oneline 3. git rebase 4. git tag 5. git cherry-pick [commit] Git basic commands for remote integration. 1. git pull origin branch_name - get the latest changes from the given branch_name to the local repo. 2. git push origin branch_name - push the changes to the remote repo. 3. git fetch Github, a Remote Repository GUI Tool for Git commands 1. gitx 2. git-cola 3. gitg What if we don’t want some files to be tracked by github? (.gitignore) References 1. https://git-scm.com/book/en/v2/ 2. http://www.makeuseof.com/tag/git-version-control-youre-developer/ 3. http://slides.com/moji3000/git_presentation/fullscreen#/3 4. http://stackoverflow.com/questions/8198105/how-does-git-store-files 5. http://www.howtogeek.com/180167/htg-explains-what-is-github-and-what-dogeeks-use-it-for/ 6. https://github.com/pricing Q&A Thank You & Demo Time