Git Yr Remote Set Up

Last week…

Jason
I started using Unfuddle for [redacted]
I like it so far.
Trey
it’s a good service
I’m going to move all my private repos there
Jason
if you just want online repo storage, why not just use your Slice?
Trey
I should do that
Jason
It’s super easy
Trey
yeah?
you should blog it
Jason
ok.

So here is how to get your remote git up and go

Setting up a remote Git repo and connecting via ssh in a nutshell:

First, we install git on the server. I’m using aptitude on Ubuntu for this. Next, we have two options: we can just set up a bare git repo and push to it using an existing user; or, if we want to be able to safely share the repo with others, we can set up a git user. After setting up the git user, we create the bare git repo, chown it to the git user, and push to it from our local machine.

On your slice…

  1. Install Git

    sudo aptitude git-core

  2. Add the Git User (If you want to use an existing user, skip to step #7.)

    sudo adduser git

  3. Set up ssh key (standard procedure)

    su - git mkdir .ssh chmod 700 .ssh nano -w ~/.ssh/authorized_keys

    (Yes, I use nano. What of it?)

    [ paste in public key and save the file ]

  4. Exit su

    exit

  5. Give the Git User a special shell that only allows git commands

    sudo nano /etc/passwd

    [ Change git’s shell from /bin/sh to /usr/bin/git-shell ]

    [ Save /etc/passwd ]

  6. If you have set up your sshd_config to only allow specific users, you’ll need to add git

    sudo nano /etc/ssh/sshd_config

    [ Add git to AllowUsers (near the end of the file), e.g.: AllowUsers jason git ]

  7. Reload sshd

    sudo /etc/init.d/ssh reload

  8. Create a dir for your repos

    sudo mkdir /var/git

    sudo chown `whoami` /var/git

  9. Create your first bare repo (--bare means no working dir; i.e. just the contents of .git)

    cd /var/git mkdir test.git cd test.git git --bare init sudo chown -R git .

Back on your local machine…

  1. Go to there

    cd /path/to/test

  2. Add your remote (just as if it were somewhere like Github)

    git remote add origin ssh://git@slice1.example.com/var/git/test.git

  3. Push all your branches

    git push --all

N.B.

  • If you use something other than Ubuntu and aptitude, your git-shell may be located somewhere else. Try which git-shell to find it.
  • If you’ve changed your ssh port to something other than 22, you’ll need to do something like this: git remote add origin ssh://git@slice1.example.com:8822/var/git/test.git
  • To allow others to contribute, put their public key in /home/git/.ssh/authorized_keys, but remember, you can’t log in as git; so, you’ll need to edit it as root with sudo.

Questions? Comments? Recommendations? Let me know.


comment feed And the ensuing discussion…

  1. 1

    Feb 8th, 2009 at 10:19 pm Trey Piepmeier

    Great writeup, Jason.

    Now put repo in the ~/bin directory of your slice and you can just type repo whatever. Then put slicerepo somewhere on the path of your local machine and type slicerepo whatever to setup the remote origin for the existing repository.

  2. 2

    Feb 8th, 2009 at 10:32 pm Jason Johnson

    Thanks, Trey. Nice shortcuts.

  3. 3

    Dec 23rd, 2010 at 9:43 pm Woodrow "asim" Jarvis Hill

    Thanks for this; your instructions (along with some tweaks for a Win32 system) were awesome! I’ve been using git locally for awhile, and with my new PC, it was time to use one repository for all coding — as well as other projects. :)

Comments are closed.



Additional Resources


Tumblelog

Tumblr

Tumblr

Delicious

Delicious

Instructional

Recent Instructional Articles

Slicehost (and Linode) LAMP Cheatsheet

17.11
16

A quick list of steps I use to set up a LAMP server on Slicehost or Linode.

Terminal Tip: Prevent Creation of Mac Dot Files

07.08
2

An environment variable can prevent creation of ._filename files.

Terminal Tip: Delete Those Mac Dot Files

08.06
4

Use the find command to delete all of the ._* and .DS_Store files.

Editorial

Recent Editorial Articles

More Usable Mac: Finder Toolbar

05.12
3

I find it useful to keep a few extra items in my Finder toolbar.

No Multiple-Class Support in IE6

18.11
9

IE6 doesn’t respond to multiple class selectors.

New Skin for the Old Blogish

07.10
8

This blogish is finally back online after an extended period of http silence.

Downloadable

Recent Downloadable Articles

Gitup!

01.02
0

Gitup + Transmit = Really Simple Publishing

Leopard-Style iTerm Icon, Take 2

18.12
8

The newer, bluer version of the iTerm icon.

Leopard-Style iTerm Icon

05.12
6

An updated, Leopard-style icon for iTerm.

About This Site

About the Author

That’s me in the photo above. My current profession is web development. Therefore, it is the subject of this site.

Postpostmodern

Postpostmodern is the name of this site and my alias on most of the web. There's nothing really special about the name Postpostmodern. I studied art in college during the years after postmodernism, and nobody knew how else to classify the state of things other than silly words like postpostmodernism.

Sorta Blogish

I'd call this a blog, but I don't feel it fits the 'log' format. My goal is to publish articles on web-related topics that interest me, and while some articles may be time-sensitive, I would prefer that the organizational focus be on the categories and tags rather than chronology.

More Me

More about me can be found on the about page. Or, look me up in the usual places: