GitHub
is awesome, really awesome for open source projects and for projects with multiple people. In
fact, if you use your own git setup for an open source project, you are
most likely hindering your project’s progress and wasting your time.
On
the other side of the coin, if you are a lone shark and you don’t need
GitHub’s awesome social features, I have news for you: you can host
your own git repositories really easily and on the cheap side.
Remote Setup
If
you are like me, you probably have a DreamHost, TextDrive or some other
cheap shared hosting account with ssh access. What you might not know
is that is all you need to host your own private git repositories.
ssh username@yourcheaphost.com
mkdir -p ~/git/yourproject.git
cd ~/git/yourproject.git
git --bare init
That
is it. Your git repository is now setup. Not too hard eh? You could put
that anywhere but a folder named git makes sense to me.
Local Setup
So
your remote server is now setup, but how do you use it? Glad you asked.
Open up a new tab (or window) or quit your ssh connection and cd to
wherever you want to setup your project locally.
mkdir yourproject
cd yourproject
git init
git remote add origin ssh://username@yourcheaphost.com/~/git/yourproject.git
touch .gitignore
git add .
git commit -m "Initial Commit"
git push origin master
At this point you have now pushed to your remote
repository and are almost good to go. The last thing is you need to add
the following on your local machine to .git/config in your project.
[branch "master"]
remote = origin
merge = refs/heads/master
The End
That
is it. You can now push and pull at will. If you want to give anyone
else commit access, just add their ssh key to ~/.ssh/authorized_keys
and you can work on the project with a friend. Setting up your own git repositories is really easy, as you can see, so don’t be afraid.
在共享主机上搭建git服务
最新推荐文章于 2023-12-31 22:10:35 发布