PDA

View Full Version : git crash course



Wizzup?
02-27-2010, 06:57 PM
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.



# 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:


#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. :)



# 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:


git push
# or:
# git push <repos> <branch>
# which is usually: git push origin master




# 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



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:

git checkout MYFILE

or add the file with git add because you made changes that you wish to save.


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
git add MYFILE plus git commit to save the change.

With svn:

svn up
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:


ssh-keygen -t rsa

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/files/TortoiseGit-1.3.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

The Claw
02-28-2010, 06:45 AM
Using a GUI

It is possible. After you have installed msysgit, install http://tortoisegit.googlecode.com/fi....6.0-32bit.msi

Thanks for this I'll just use the GUI :)

Wizzup?
02-28-2010, 12:33 PM
Thanks for this I'll just use the GUI :)

Can you explain how to use it? I quickly tried it and it looked alright, but I didn't want to take all the pictures etc.

I think it has
git ->
...Push
...Pull
...Clone
...Git Commit
...Much more

So that should be fine too.

Also, if you type ``git gui'' in bash there's a GUI as well,but I think that one is more for looking at the source tree. At least it can help you generate your key.
Note that you'll still need msysgit for tortoisegit.

BraK
08-12-2011, 11:53 AM
you should probably move this into the tutorial section. :)

~BraK

Shuttleu
08-12-2011, 10:59 PM
i read somewhere not to use pull, but to use fetch and merge instead

~shut

Nava2
08-13-2011, 01:03 PM
i read somewhere not to use pull, but to use fetch and merge instead

~shut

pull is synonymous to the two together.

Wizzup?
08-13-2011, 02:51 PM
pull is synonymous to the two together.

No; it's not. Shuttleu is right, I linked that yesterday, but it's advanced stuff and beyond the scope of a simple crash course. :)

Reference: http://longair.net/blog/2009/04/16/git-fetch-and-merge/

Coh3n
08-13-2011, 03:42 PM
Moved to tutorial island.

Bixby Sayz
08-20-2011, 12:30 AM
I can pull anything that is hosted on github just fine, but I'll be damned if I can get the srl open-dev off http://git.villavu.com/srl-opendev.git/. Complains it can't find the head?

Wizzup?
08-20-2011, 08:39 AM
I can pull anything that is hosted on github just fine, but I'll be damned if I can get the srl open-dev off http://git.villavu.com/srl-opendev.git/. Complains it can't find the head?

Yeah, that's not the GIT url. It's only a web interface.

I've exported it for you, try git clone git://villavu.com/srl-opendev.git
(It's read only, and it's rather large too due to the SPS push and revert)

Bixby Sayz
08-21-2011, 10:43 PM
I've exported it for you, try git clone git://villavu.com/srl-opendev.git
(It's read only, and it's rather large too due to the SPS push and revert)

I'm just going to nod my head and pretend like I understand. Seems to have worked.

Wizzup?
08-22-2011, 11:01 AM
I'm just going to nod my head and pretend like I understand. Seems to have worked.

The git URL itself really has very little to do with git; the url I just gave you in my previous post wouldn't have worked before, either. Until I set it up.