I have many local git repos on my OSX. Using command line I want to make new gitlab repos on https://gitlab.ccompanyname.com, form existing local repos.
Is it possible to do that?
I have many local git repos on my OSX. Using command line I want to make new gitlab repos on https://gitlab.ccompanyname.com, form existing local repos.
Is it possible to do that?
2018 Solution: just use
--set-upstream
Assuming you'll take care of writing the script that would do the following for each of your local repo, it seems that as of Gitlab 10.5 you can simply use
This will create a new project on Gitlab without you creating it manually on the server
From the Documentation
Push to create a new project
Create new empty projects in GitLab for each of your local repos you want to push to GitLab. After you create the project's, you will be taken to the default project page.
Then cd into each of your existing git repos. Do a
git remote add origin <your new gitlab repo address>
And then a
git push -u origin master
You will need to do this for each of your repos you want to add.
Your repo address is given to you on the project page. As http and/or ssh. If you already have a remote called origin on your local machine, you might want to rename it first. Or you can call the gitlab one something different. Also if you want to push all your branches to gitlab you can do a
git push --all origin
If you want your tags,git push --tags origin
If you use nodejs, or even have a simple understanding of it, the node-gitlab module is great. On a self hosted Gitlab instance I've been able to create projects and import the repos from a remote repository (a local git server). The process should be similar for a local repository. You could setup a local git server on your machine and use that as the import_url for each Gitlab project.
Or, you can write a script that will use the API to create the project then push each repository to its respective project.
Pseudocode: for each repo in directory:
I have to agree with you that documentation for Gitlab's API wrapper third-party applications is not ideal, however I did manage to make one of them work.
For this, I set up a sandbox gitlab server (GitLab Community Edition 8.0.5) in a vagrant box running Ubuntu 14.04.
Now, the API wrapper I used is this one (python-gitlab by Gauvain Pocentek). I chose this one because it is starred by enough people (118 at time of writing) and it's written in python so portability will not be an issue (my host machine is Windows with cygwin, but I will be using unix syntax for this answer).
Installation is quite easy with
pip
:Once installed you will have to modify a config file -that does not exist out-of-the-box or, at least, I could not locate it- (the documentation was not clear about this). This file's "official" name is
.python-gitlab.cfg
and this is the one that config.py is searching by default.Anyway, I created my own version of
.python-gitlab.cfg
based on the sample syntax found at the project's github which goes like this:You will have to get yourself a private token from the web interface (found in Profile Settings :: Account) since, as the README points out,
After this is taken care of, creating a project can be achieved like this, for
http
:and like this for
https
:The switches used above, can be found by looking at the help:
Now, assuming that you have taken care of SSH keys (both locally and in the web interface), and that you want the gitlab repo names to be the same as the directories in your local git, then, a little
bash
script like the following, can automate the project creation and the local repos push:What it does is create gitlab projects named after the dirnames found at the outer local git directory, then
cd
's into each one of them, renews the origin and then performs the push.One thing to mention here is that gitlab converts repo urls to lowercase, for example
sampleRepo001
becomessamplerepo001
in the repo's url; that's why I convert dirnames to lowercase in the script.And, finally, here is an example run of the script:
As a reminder, if you want to use this script, test thoroughly before applying to the actual production server.
Update - I added some more info on how to handle HTTPS/SSL.