git: simple!

I’ve been working on a project at home, using git for source control, and needed to make the project available from anywhere, so that I could work on it wherever I needed to. I have an ssh account at the university, so I decided I’d try setting up a git repo I could access through that. I was expecting it to be complicated and difficult, but in fact it was incredibly simple.

Google found these instructions, which I based my setup off; most of what’s below is quoted from that article, but I’ll put it here anyway for reference.

# login to remote server
ssh -l myUsername REMOTE_SERVER
# once logged in
mkdir /path/to/example.git
cd /path/to/example.git
git init

Note: the link above recommends

git --bare init

in the last line. using the –bare switch will create a repo without a working tree, which is great if you don’t need to work on the code on the machine where the repository is housed. However I need to work on the code on that machine too when I’m at uni.

Then, on my home machine I just run:

git remote add origin myUsername@REMOTE_SERVER:/path/to/example.git
git push origin master

The first command adds a the remote repository we just created and names it ‘origin’. The second command then pushes your ‘master’ branch to the remote repo.

And that’s it! You can now push/pull/clone from this repo to your heart’s content. For example after I work on the code at uni then want to work on it at home with those changes I just do:

git pull origin master

Simple!