Few assumptions:
- You've worked with SvN before.
- You don't mind using the command line. (Actually you don't need to but I'll focus on using the command line.)
- You are probably on Windows: install msysgit with GitBash as shell.
- You want to learn git.
I'll list some basic actions of git, and along them list their somewhat equivalent svn commands.
To check out a repository, use git clone.
Code:
# Read only access
git clone git://github.com/SRL/SRL-5.git
# If you have send me your pub key, check out a read/write repo:
git@github.com:SRL/SRL-5.git
# Authentication is done purely with public keys.
In svn we use:
Code:
#Read-write. write is done with http:// authentication. (webdav)
svn checkout http://villavu.com/repositories/srl5
(Or with the GUI, svn -> Checkout)
Adding files to the repos and committing changes (locally) with git add and git commit
It is important to understand that when you commit with git, you only commit locally. This gives you the huge advantages of splitting up your changes into several commits, which you can all send to the real repos later.
It is also worth to note that git by default doesn't commit anything. You have to add the files you want to commit. svn on the contrary commits all files by default, which I personally find highly annoying.
Code:
# Add files that we want to commit
git add README.txt
git add LICENSE.txt
# Commit with message (-m)
git commit -m "Adding readme and license"
# Now, we locally stored this commit. We need no internet connection,
# and we don't need an actual valid account on the main git repos.
# (read: everyone can do this, non devs as well, since it is all local)
We can do several other commits.
Now, once we are done, we send our changes with:
Code:
git push
# or:
# git push <repos> <branch>
# which is usually: git push origin master
Code:
# note that this already commits all your changes to the main repos
# and you will need a working internet connection AND repos account to do so.
svn commit README.txt LICENSE.txt
Updating your current source tree with git pull
Code:
git pull
# or:
# git pull <repos> <branch>
# which is usually: git pull origin
If some files are locally changed and not committed yet, git will not continue until you either restore the files with:
Code:
git checkout MYFILE
or add the file with git add because you made changes that you wish to save.
Code:
git add MYFILE
# as I'm doing this completely out of my head, I'm not sure if you also need to git commit.
If git cannot automatically merge the two files, it will ask you to do it manually. Edit the files correctly and use plus git commit to save the change.
With svn:
It will bug the hell out of you if a file changed, and the merging process is even more annoying. Simply replacing a file can take ages.
Branching and Merging
Braching and merging is where git really shines. I don't believe most of you have ever branched or merged, so I won't cover this for now. If you are interested: http://git.or.cz/course/svn.html#branch
Distributed?
git is distributed. This basically means everyone has a complete copy of the source tree and revision history. This implies:
- You can always access the entire history, and check out any revision locally. You don't need an internet connection to the server.
- Everything is much faster, since no internet is required. (When it comes to latency, internet is a real bitch)
- You have the complete source tree! With git you can simply choose to stop using the main repos and create your own `main' repos. People can push and pull from your repos as well. (This is only useful if you have a have some sort of webserver I guess)
The last point is very interesting.
Imagine the following situation:
Wizzup has full access to the ``main'' repos. (The one that is generally regarded to be the stable one)
Wizzup fully trusts Benland, Niels, Raymond and Markus. If they make any changes to their repos, wizzup will happily pull from their reposses.
Wizzup does not trust Newcomer A. However, Markus knows newcomer a pretty well. If newcomer A makes a change to his repos, he asks markus to pull from his repos. Markus quickly sees the changes are fine, and then asks Wizzup to pull from his (Markus') repos, and then newcomer A's code went mainline.
Now, this is pretty cool, but I don't think we will use this situation in the near future. So I think it would be best to give all SRL Developer access to the main repos (doh).
How do you get an account?
Open "GitBash" (installed by msysgit)
Type the following:
Optionally choose a password. Or leave it empty.
Now you will have a file id_rsa and id_rsa.pub in C:\Documents and Settings/All Users/Your User/.ssh/
Send id_rsa.pub to me, and I will add your account. You will need to do this per computer.
Note: If this turns out to suck, I can see if I can get webdav to work. (So you can have the usual accounts + passwords. (The same ones that you use for the svn)
Let's see if we can get this to work.
Using a GUI
It is possible. After you have installed msysgit, install http://tortoisegit.googlecode.com/fi....6.0-32bit.msi
Final notes:
If you think git is too complex, please voice your opinion. We can still use svn if this turns out to be annoying to use.
If you want to learn more about git, use google and you'll find plenty of tutorials.
http://github.com is a cool site to host your own git reposses for free.
SRL5 online view: https://github.com/SRL/SRL-5