Creating a remote Git repository - cheatsheet
This really is a dead simple process for those times you want to create a private Git remote for yourself/development team. Just another reason why Git is so damm cool for version control.
- Ensure you can
ssh user@targetserver
successfully- Public/private keys are a smart choice here
- On
targetserver
- Example here assumes all Git repository users are members of a
gitusers
group, adjust to suit mkdir -p ~/path/to/repository
cd ~/path/to/repository
-
git init --bare --shared=group
- Switch
--shared=group
will addcore.sharedrepository = 1
to the repositories~/path/to/repository/config
file
- Switch
-
Note: a 'bare' repository will not house it's meta data in a separate
.git
directory, since there is no concept of a working copy. chgrp -R gitusers ~/path/to/repository
- All done on
targetserver
- Example here assumes all Git repository users are members of a
- Now back on our development machine lets push a working copy
mkdir -p ~/my/new/working/copy
cd ~/my/new/working/copy
git init
touch somefile.txt
git add .
git commit -m 'Initial commit'
git remote add origin user@targetserver:path/to/repository
git push -u origin master
git fetch
git pull
Written by Peter Mescalchin
Related protips
7 Responses
What if I want to deploy the code on the same development server on each commit?
What's the best way to do this?
@dpashkevich very simple infact - a quick search turned up this which will give you exactly that http://caiustheory.com/automatically-deploying-website-from-remote-git-repository the magic sauce is in core.worktree and the hooks/post-receive script.
@magnetikonline I read about that. There seems to be two major approaches:
1) make the repo non-bare with its working tree pointing to live website path (as suggested in the article you shared). Post-receive hook on the repo checks out the worktree.
2) actually init two repos on your development server: first one will be bare and used by developers for pushing/pulling and the second one would be a regular repo at live website path. Post-receive hook on the bare repo navigates to the live website repo and does a pull from the former.
The first approach looks like less steps to make (and no extra repo) but feels like some kind of hack. Also, it's less flexible than the second approach - it only works when the repo is on the same machine as the website and you are not allowed to edit the working directory. I was wondering if there are any other pitfalls besides mentioned with the two approaches and which one do people actually prefer.
@dpashkevich I really can't say - since I typically deploy using rsync and some custom PHP scripts to minify CSS/JS and bundle assets (which I hope to clean up and put on GitHub someday....).
Ok, thanks for sharing your experience anyway! I'm just curious how other people do it.
Git Git Git everywhere. i have installed it, but am not getting it. can you give me a heads up and how to go about it. because i don't do version control when developing. and my Git is on windows platform. Thank in advance.
@wifisoftinc suggest you start here: http://git-scm.com/book