AGV, IIT Kharagpur September 13, 2012
Outline 1 Version control system What is version control Why version control 2 Introducing GIT What is GIT? 3 Using GIT Using GIT for AGV at IIT KGP Help and Tips
What is version control? A version control system (also known as a Revision Control System) is a repository of files The easiest way to understand the concept of version control is to think of it as of the file history in Photoshop. Version control is much better than history in Photoshop: you also get a never-ending "undo", effortless backup, peace of mind, and a more organized way of storing different versions of your work. Additionally multiple people people can work in the same project at the same time.
How we manage it without VCS How do we Share code? Who do we determine who have the latest code? Can you really judge which one is actually latest? How do we merge work of team members? How do we go back to old code?
Why is version control important? File names and directory structures that are consistent for all team members. Making changes with confidence, and even reverting when needed. Relying on source control as the communication medium for your team. Easily work on different versions of your code. Understanding who made a change and when it happened.
Version Control is not a Backup System Having your files backed up on a remote server is a nice side effect of having a version control system. But you should not use your VCS like it was a backup system. Specially do not add binary file that are not needed to be tracked. Pay attention to committing semantically (see related changes ) To ignore files/folders in GIT, add them to.gitignore file.
Is Version Control only for source code? You can keep all kind of documents. Mechanical drawings, cad files. Circuit diagram files. For sharing excels/docs google docs may be used, and GIT can also be used. It might be a good idea to have separate repository for some of these tasks.
What is GIT? Git is a version control system. Speed Simple design Strong support for non-linear development (thousands of parallel branches) DVCS: Fully distributed (uses Hashes instead of revision numbers) Able to handle large projects like the Linux kernel efficiently (speed and data size)
Centralized Vs. Distributed
Git installation Windows Install msysgit for core functionality and TortoiseGit for user-friendly GUI. Linux (Ubuntu) Install git-core (sudo apt-get install git-core) There are many git interface available in the software center, which you can find by searching git" RabbitVCS integrates with file-manager and support GIT, SVN and Mercurial. Follow instructions from web-page to install. http://www.webupd8.org/2011/01/rabbitvcs-perfecttortoisesvn.html
Global settings and proxy Configure the user which will be used by git Add your name git config --global user.name Example Surname" Same for the email address git config --global user.email your.email@gmail.com" And most importantly add IIT KGP proxy git config --global http.proxy http://144.16.192.216:8080 All these settings are saved in /.gitconfig which you can edit manually too.
Create Create a new repository OR git init Checkout a repository git clone /path/to/repository git clone username@host:/path/to/repository (default protocol is ssh) git clone http://<username>@git.assembla.com/agv.git (we use this for http access behind IIT proxy) git clone http://<username>:<password>@git.assembla.com/agv.git
Workflow Your local repository consists of three "trees" maintained by git. The first one is your Working Directory which holds the actual files. The second one is the Index which acts as a staging area and finally the HEAD which points to the last commit you ve made.
Add, remove, move You can propose changes (add it to the Index) using git add <filename> The following command can be used to add all files, be careful to not add junk files, by setting.gitignore file properly. git add. To remove files(do not delete directly) git rm <filename> To move files/folders(do not move directly) git mv <filename>
Commit You can propose changes (add it to the Index) using git add <filename> This is the first step in the basic git workflow. To actually commit these changes use git commit -m Commit message" Now the file is committed to the HEAD, but not in your remote repository yet. To commit all local changes in tracked files with message use git commit -a -m Commit message" To amend local commit git commit -m initial commit git add forgotten_file git commit --amend
Pushing changes Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute git push origin master Change master to whatever branch you want to push your changes to. If you have more remote locations configured you can use them in place of origin.
Update & merge To update your local repository to the newest commit, execute git pull It fetch and merge remote changes in your working directory. Git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged with git add <filename> Download all changes from <remote>, but don t integrate into HEAD git fetch
Branching Branches are used to develop features isolated from each other. The master branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion. create a new branch named feature_x" and switch to it using git checkout -b feature_x
Branching contd. switch back to master git checkout master switch back to feature_x" git checkout feature_x" and delete the branch git branch -d feature_x a branch is not available to others unless you push the branch to your remote repository git push origin <branch> to merge another branch into your active branch (e.g. master), use git merge <branch> Before merging changes, you can also preview them by using git diff <source_branch> <target_branch>
Local Changes Files changed in working directory git status Changes to tracked files git diff Changes between ID1 and ID2 git diff <ID1> <ID2>
Commit History Show all commits, starting with newest git log Who changed what and when in a file git blame <file>
Undo Discard all local changes in your working directory you cannot undo a hard reset git reset --hard HEAD Discard local changes in a specific file git checkout HEAD <file> Revert a commit (by producing a new commit with contrary changes) git revert <commit-id> <commit-id> can be any hash-id of commit or HEAD.
Tagging It s recommended to create tags for software releases. You can create a new tag named 1.0.0 by executing git tag -a 1.1 -m "tag description" tag specific commit git tag 1.1 <commit-id> push tags git push --tags delete local tag git tag -d 1.0 delete tag from remote git push origin :refs/tags/1.0
Ignore certain files Git can be configured to ignore certain files and directories. This is configured via the.gitignore file. This file can be in any directory and can contain pattern for files. Ignore all bin directories bin Ignore all files ending with * You can also setup a global.gitignore file valid for all Git repositorie. Create a /.gitignore in your user directory. Configure Git to use this file as global.gitignore git config --global core.excludesfile /.gitignore
Keep directory structure Git will ignore empty directories, e.g. do not put them under version control. If you want to track such directories, is it convention to put files called ".gitkeep" in these directories. The file could be called anything; Git assigns no special significance to this name. As the directory now contains a file, Git will include it into its version control mechanism.
Tips for version control success Pull changes before you start working Make small commits (don t commit a whole day s work) Compile before commit Diff before commit Write useful messages
Other interesting commands to look at stash submodule rebase more at http://git-scm.com/docs/
Help & Documentation Get help on the command line $ git help <command> Official Git Website http://www.git-scm.com/ Free online resources http://progit.org http://book.git-scm.org http://gitref.org http://github.com/alexzeitler/gitcheatsheet http://www.kernel.org/pub/software/scm/git/docs/everyday.html http://www.vogella.com/articles/git/article.html http://ndpsoftware.com/git-cheatsheet.html
Thank you