I’ve just spent a day learning about GIt - we’re starting on a big project over the summer with additional developers and we’ll need a source control system. It’s been a bit of a steep learning curve as I’ve had to learn about versioning systems from scratch as well and now my brain needs to download.
So here is the fuckwits guide to starting a git-based project.
First of all, install Git. On Ubuntu that’ll be:
sudo apt-get install git-core
I don’t care what it is on other systems, as I don’t use them. Go figure it out yourself.
If you’re in an organisation then you’ll probably want a central repository. Choose the machine the repo will live on, install git-core, create a new user to own your repo (I’ve just called it “git”) and create a directory for you new project to live in (I just create a folder in the git user’s home dir).
sudo adduser git
su git
cd ~/
mkdir projecthome
cd projecthome
You’ll now need to make this folder into a git project:
git init
Fucking chavs are even in SCMs now (”give me yer money, init!?”).
Create a file, just to test things.
touch index.php
You’ll now need to tell git that you’re thinking of commiting this file to the repo.
git add index.php
or to add everything in the dir:
git add .
Once you’ve added any files you’ll need to commit them. This is the big deal and what Git is all about:
git commit -m "This is the first commit of the project"
The message is very important, as it tells other people what you did in this commit.
To see what you just did, type:
git log
Woo, you now have a project. You may now do a small dance.
Now switch to the machine where you will actually do your work on. You’ll need to make a copy of the repo on your repo server (make sure git-core is installed):
git clone git@<yourserveraddress>:/home/git/projecthome/
You’ll see some gumph appear and hopefully if you do an “ls” you’ll see:
index.php
Nice! You’ve got a working copy from a remote repo.
Now, try adding a new file here:
touch another.php
You’ll need to tell Git you want to add this file to your local repo:
git add another.php
And now we’ll commit it to the local repo:
git commit -m "I've just added another file"
And check out the log to see what has been done:
git log
Now, at this point you’ve committed your changes to your local copy (remember the clone?) of the project repo. Nothing wrong with that - you’ve got content versioning going on and can do all kinds of fancy things. However, none of your coworkers can see the changes you’ve made. Not much use really. Therefore you’ll push those changes back to the central repo, with, erm:
git push
Woo! Now everyone else can access the changes you’ve made.
If one of your co-workers makes a change on their copy of the repo and pushes it back to the central repo you’ll need to pull it back down. It’s just as obvious a command again:
git pull
Any changes they’ve made will show up in your directory.
I’m going to brain dump some more here later on. For now I’m off to figure out branching and merging…