#Git Lecture Notes
##Topics Discussed
- SSH, public key authentication.
- Version Control
- Git Basics
- Git Workflow
- Github
- Extra git commands
- Git GUI's
##SSH
###Installing ssh
sudo apt-get install openssh
###Connecting to server
$ ssh username@hostname
###Public key authentication
ssh-keygen -t rsa
The private key is at ~/.ssh/id_rsa
while the private key is at ~/.ssh/id_rsa.pub
The server needs your public key to authenticate the connection.
##Version Control
- central VCS v/s Distributed VCS
- Why Version Control
- Helps remember history of project
- Move back and forth in history
- Any break in code can be fixed easily
- Any bugs introduced can be traced back to the code that made it
- Examples : svn, cvs, mercurial, bzr, etc
##Git Basics This is just a simple walkthrough. You are encouraged to try out these steps on your own.
git init
creates a new repositorygit add <filename>
adds files to indexgit add .
adds everything to indexgit commit
creates a commitgit commit -a
adds all modified files to the index and starts a commit- A blank commit message aborts the commit
git checkout <??>
changes your working directory to a commit/tag/branchgit checkout -b branchname
creates a new branch and shifts to itgit branch
shows a list of all branches & the current branchgit merge branchname
merges the branch with the current branchgit tag
marks a tag for the current commit
##Little of git-jargon Read more over here
branch
is an active line of development.commit
is a snapshot of the working directorytag
is an alias of a particular commitHEAD
is a pointer to the current checked out branchtree
is the internal representation of working directory in gitblob
is the internal representation of files in gitindex
is a staging area for the commit in progress
##Git workflow
Mainly from here
Topics include branches, stable, hotfix, release, development, feature branch etc.
##Github
- http://github.com is an awesome site that allows people to share code, projects and colloborate easily using git.
- Create an account
- Setting up ssh-keys
- Creating repository
- Setting
remotes
push
,pull
,fetch
,merge
- Github gem
##Some other things
git log
allows you to see your historygit log --oneline
gives single line historygit log --pretty
gives better outputgit log --graph
shows your commit graph- Git GUI Systems -
gitg
,git-cola
,qgit
,giggle
and the windows git-gui as well. .gitignore
file to store system specific stuff (configuration, databases, temp files, cache, build)
##Redmine
- Create user accounts
git config user.name
andgit config user.email
should be setup- Pass along the public keys (via email)
##Commit Messages Editing
When you make commits on git, it uses your default text editors to type the commit message. This is set to vim
in Windows and Linux. Linux folks can change it to anything else by setting the $EDITOR variable by the following command:
export EDITOR=nano
(Replace nano with the editor of your choice like gedit geany etc)
You can also save the setting in your git global configuration, by :
git config --global core.editor "nano"
As per this question on SO, you can use Notepad++, or notepad etc on git on Windows as well.
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Take care about the slashes, and the path to your editor of choice. Don't use notepad, it screws with the newlines.
###Vim If you're stuck with vim for some reason, do the following in the commit window
- Press
i
to go to insert mode - Type your commit message
- Press
Esc
- Type
:wq
. The colon is important - Press
Enter
- That's it, your commit should be successful
Remember, an empty commit message aborts the commit. Also the best way to commit easily is:
git commit -m "Commit Message Here"
to just type the commit message on the command line, and leave out all the hassle of the editor
#Resources on Git
- Git Cheat Sheets & Excellent starting guide
- Everyday GIT With 20 Commands Or So
- Pro Git Book
- Git Reference
- Git Tutorial
- Git Community Book
- Another git tutorial
- Git beginner tutes
- Git for Computer Scientists
- Git from bottom up
- http://learn.github.com/p/intro.html - contains video tutorials on how to use git.
- There is this book : Pragmatic Version Control , Using Git. you could download it from <library.nu>