Git: Setting up a remote repository
In case you missed the news, UbuntuOne is shutting down. This has caused me a headache, as I've relied on it for syncing copies of my code & local git repos -- Yes, that was a horrible way of doing things, but it was quick and easy. -- as well as some other files I didn't want to loose. My solution to the current dilema has been two fold:
- GitHub for the code that I'm not concerned about being public, and
- Repo's on various servers I work with for private code.
All the info on working with GitHub is easy enough to find, and it is an excellent site to use. I'm growing more fond of it all the time. But working with a generic remote repo through SSH, while easy, doesn't seem to have the support.
Infact the big git manual git-scm.com/documentation when discusing working with remote repositories, uses GitHub as an example, no mention of setting up your own remote server. Oops, didn't read enough, it does cover this.
How do you do it?
You have to have SSH set up on your working machine and Server, as well as Git (obviously).
On the remote server, set up a new bare repository. For the purpose of this example, I'm going to assume you are going to put your git repositories in your home directory on the server in a folder named "git/" your username is "myuser" and the server is "servername.net"
# In your /home/myuser/git/ directory ~/git$ mkdir newproject.git # where newproject is the name of your project, the .git is just to identify the folder as a repo to humans ~/git$ cd newproject.git ~/git/newproject.git$ git init --bare #the --bare is important, it signifies that the repo is empty # you can exit the server now
On the local machine, assuming you havent already started a git repo.
# Where ever your project is, that is where you should go ~/newproject$ git init ~/newproject$ git add --all ~/newproject$ git commit -m "Getting ready to push to remote" ~/newproject$ git remote add origin firstname.lastname@example.org:/home/myuser/git/newproject.git ~/newproject$ git push -u origin master
And that is it. You can push to it, clone from it, and do all your other Gitty goodness to it.
One final note. If you are doing your coding on a Windows machine, you can still use Git and push to *NIX servers. Install Git-Bash for Windows and you can set up your SSH the same way as you would in *NIX with a .ssh directory in your home directory.