Reputation: 768
I'm trying to build an easy way for me to create & push repositories to my own server. Currently, I have to create a --bare
repository on my server first before I can push to it.
However, I'd like to be able to dod something like this
git remote add origin https://[email protected]/user/new-repo.git
git push -u origin master
and then on the server, if new-repo.git
doesn't exist under user
on my server, it'll create it and continues to receive objects normally.
So, how can that be achieved on the git server?
Upvotes: 1
Views: 74
Reputation: 555
If you are using gitlab as git-server, try this:
Push to create a new project
Introduced in GitLab 10.5.
When you create a new repository locally, instead of going to GitLab to manually create a new project and then clone the repo locally, you can directly push it to GitLab to create the new project, all without leaving your terminal. If you have access rights to the associated namespace, GitLab will automatically create a new project under that GitLab namespace with its visibility set to Private by default (you can later change it in the project’s settings).
This can be done by using either SSH or HTTPS:
## Git push using SSH
git push --set-upstream [email protected]:namespace/nonexistent-project.git master
## Git push using HTTPS
git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master
If you are not using gitlab, I suggest you give it try.
You can deploy a gitlab-ce
docker container on your ubuntu, it's pretty easy.
PS: I think gitlab do the automatic repo creating by hacking the ssh. So you can do this by just combine:
git clone --bare my_project my_project.git
cp -Rf my_project/.git my_project.git
and scp -r my_project.git [email protected]:/srv/git
. You can refer to the official doc for more.
Upvotes: 1