How to create a new gitlab repo from my existing local git repo, using CLI?












34















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?










share|improve this question























  • From your url I assume that you are running a gitlab server. According to the documentation of the Gitlab CE, there are third-party appications that are wrappers/CLIs for the API. Maybe one of these might be helpful.

    – sokin
    Oct 13 '15 at 12:48











  • i tried tools given of that page. documentation is not clear to me

    – Jitendra Vyas
    Oct 13 '15 at 13:24











  • Since GitLab 10.5 (Feb 2018), it is possible to simply push to create a new project on GitLab. @JitendraVyas consider accepting ted's answer below to improve the visibility of this solution.

    – joelostblom
    Apr 24 '18 at 22:32











  • It's worth noting that if you create a new project on gitlab the blank project then comes up with detailed instructions for all manners of ways to get your code into it :-)

    – Bananaapple
    May 3 '18 at 7:58
















34















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?










share|improve this question























  • From your url I assume that you are running a gitlab server. According to the documentation of the Gitlab CE, there are third-party appications that are wrappers/CLIs for the API. Maybe one of these might be helpful.

    – sokin
    Oct 13 '15 at 12:48











  • i tried tools given of that page. documentation is not clear to me

    – Jitendra Vyas
    Oct 13 '15 at 13:24











  • Since GitLab 10.5 (Feb 2018), it is possible to simply push to create a new project on GitLab. @JitendraVyas consider accepting ted's answer below to improve the visibility of this solution.

    – joelostblom
    Apr 24 '18 at 22:32











  • It's worth noting that if you create a new project on gitlab the blank project then comes up with detailed instructions for all manners of ways to get your code into it :-)

    – Bananaapple
    May 3 '18 at 7:58














34












34








34


14






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?










share|improve this question














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?







git gitlab






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 13 '15 at 11:50









Jitendra VyasJitendra Vyas

58.4k196503791




58.4k196503791













  • From your url I assume that you are running a gitlab server. According to the documentation of the Gitlab CE, there are third-party appications that are wrappers/CLIs for the API. Maybe one of these might be helpful.

    – sokin
    Oct 13 '15 at 12:48











  • i tried tools given of that page. documentation is not clear to me

    – Jitendra Vyas
    Oct 13 '15 at 13:24











  • Since GitLab 10.5 (Feb 2018), it is possible to simply push to create a new project on GitLab. @JitendraVyas consider accepting ted's answer below to improve the visibility of this solution.

    – joelostblom
    Apr 24 '18 at 22:32











  • It's worth noting that if you create a new project on gitlab the blank project then comes up with detailed instructions for all manners of ways to get your code into it :-)

    – Bananaapple
    May 3 '18 at 7:58



















  • From your url I assume that you are running a gitlab server. According to the documentation of the Gitlab CE, there are third-party appications that are wrappers/CLIs for the API. Maybe one of these might be helpful.

    – sokin
    Oct 13 '15 at 12:48











  • i tried tools given of that page. documentation is not clear to me

    – Jitendra Vyas
    Oct 13 '15 at 13:24











  • Since GitLab 10.5 (Feb 2018), it is possible to simply push to create a new project on GitLab. @JitendraVyas consider accepting ted's answer below to improve the visibility of this solution.

    – joelostblom
    Apr 24 '18 at 22:32











  • It's worth noting that if you create a new project on gitlab the blank project then comes up with detailed instructions for all manners of ways to get your code into it :-)

    – Bananaapple
    May 3 '18 at 7:58

















From your url I assume that you are running a gitlab server. According to the documentation of the Gitlab CE, there are third-party appications that are wrappers/CLIs for the API. Maybe one of these might be helpful.

– sokin
Oct 13 '15 at 12:48





From your url I assume that you are running a gitlab server. According to the documentation of the Gitlab CE, there are third-party appications that are wrappers/CLIs for the API. Maybe one of these might be helpful.

– sokin
Oct 13 '15 at 12:48













i tried tools given of that page. documentation is not clear to me

– Jitendra Vyas
Oct 13 '15 at 13:24





i tried tools given of that page. documentation is not clear to me

– Jitendra Vyas
Oct 13 '15 at 13:24













Since GitLab 10.5 (Feb 2018), it is possible to simply push to create a new project on GitLab. @JitendraVyas consider accepting ted's answer below to improve the visibility of this solution.

– joelostblom
Apr 24 '18 at 22:32





Since GitLab 10.5 (Feb 2018), it is possible to simply push to create a new project on GitLab. @JitendraVyas consider accepting ted's answer below to improve the visibility of this solution.

– joelostblom
Apr 24 '18 at 22:32













It's worth noting that if you create a new project on gitlab the blank project then comes up with detailed instructions for all manners of ways to get your code into it :-)

– Bananaapple
May 3 '18 at 7:58





It's worth noting that if you create a new project on gitlab the blank project then comes up with detailed instructions for all manners of ways to get your code into it :-)

– Bananaapple
May 3 '18 at 7:58












5 Answers
5






active

oldest

votes


















47














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






share|improve this answer



















  • 6





    "Create new empty projects in GitLab" this was the question. I want to do it from CLI

    – Jitendra Vyas
    Oct 15 '15 at 12:05











  • maybe we should git remote remove origin first

    – MichaelMao
    Apr 24 '17 at 7:25



















17














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



git push --set-upstream address/your-project.git


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




When you create a new repo locally, instead of going to GitLab to manually create a new project and then push the repo, you can directly push it to GitLab to create the new project, all without leaving your terminal. If you have access to that namespace, we 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 HTTP:




## Git push using SSH
git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master

## Git push using HTTP
git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master



Once the push finishes successfully, a remote message will indicate the command to set the remote and the URL to the new project:




remote:
remote: The private project namespace/nonexistent-project was created.
remote:
remote: To configure the remote, run:
remote: git remote add origin https://gitlab.example.com/namespace/nonexistent-project.git
remote:
remote: To view the project, visit:
remote: https://gitlab.example.com/namespace/nonexistent-project
remote:





share|improve this answer

































    8














    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:



    $ sudo pip install python-gitlab


    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:



    [global]
    # required setting
    default = local
    # optional settings
    ssl_verify = false
    timeout = 5

    [local]
    # url = http://10.0.3.2:8080
    # get the private token from the gitlab web interface
    # private_token = vTbFeqJYCY3sibBP7BZM

    [remote]
    url = YOUR SERVER URL GOES HERE
    private_token = YOUR PRIVATE TOKEN GOES HERE
    ssl_verify = false

    [remote-ssl]
    url = YOUR HTTPS URL GOES HERE (eg https://gitlab.ccompanyname.com))
    private_token = YOUR PRIVATE TOKEN GOES HERE
    ssl_verify = true (VALID CERTIFICATE) OR false (SELF-SIGNED CERTIFICATE)


    You will have to get yourself a private token from the web interface (found in Profile Settings :: Account) since, as the README points out,




    Only private token authentication is supported (not user/password).






    After this is taken care of, creating a project can be achieved like this, for http:



    $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote project create --name YOUR_PROJECT_NAME


    and like this for https:



    $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote-ssl project create --name YOUR_PROJECT_NAME




    The switches used above, can be found by looking at the help:



    $ gitlab --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:



    #!/usr/bin/bash

    cd 'PATH/TO/YOUR/REPOS/DIRECTORY' # enter your local repos dir here
    server="YOUR SERVER" # enter your server URL
    user="YOUR USER" # enter your user name
    gitlab_cfg="PATH/TO/YOUR/.python-gitlab.cfg" # enter the location of config file
    #method="remote" # uncomment for http, comment for https
    method="remote-ssl" # uncomment for https, comment for http
    for i in $( ls -1 ); do
    echo
    echo
    echo '>> Creating Project'
    gitlab -c $gitlab_cfg --gitlab $method project create --name $i
    echo '>> Project ' $i 'created'
    echo '>> ------'
    cd $i
    li=$( tr '[A-Z]' '[a-z]' <<< $i) # convert dirname to lowercase, safe with older bashes (<4)
    origin="git@$server:$user/$li.git"
    echo ">> Reassigning origin to : $origin"
    git remote rm origin
    git remote add origin $origin
    git remote -v
    echo '>> Pushing local repo to gitlab'
    git push -u origin master
    echo '>> Done'
    echo
    echo
    cd ..
    done
    echo
    echo 'Operation finished'


    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 becomes samplerepo001 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:



    enter image description here



    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.






    share|improve this answer

































      1














      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:




      • Use API to create project on gitlab.com

      • git remote add gitlab url-to-gitlab-repo

      • git push gitlab --mirror






      share|improve this answer

































        0














        git-repo has done the dirty jobs for you. It also supports GitLab, GitHub and Bitbucket.



        1. Installation



        apt-get install python-pip
        pip install git-repo


        you might need pip3 if the above command is not working.



        (optional)
        apt-get install python3-pip
        pip3 install git-repo


        2 Configuration



        2.1 necessary configuration



        git repo config


        The command line tool, step by step, will ask if you want to set up bitbucket, github, gitlab account, press 'y/n' and username/password accordingly. If you do not know what it means, press 'n' to skip. The configuration file will be generated in ~/.gitconfig. You may want to tweak it afterwards.



        (optional) for example, you could manually set token in ~/.gitconfig like this:



        [gitrepo "gitlab"]
        token = xxxxxxx
        [gitrepo "github"]
        token = xxxxxxx


        2.2 better shortcut



        append following lines to ~/.gitconfig.



        [alias]
        hub = repo hub
        lab = repo lab


        why?



        Because now you could simply use shortcut
        git lab clone /howto
        git hub clone /howto
        in the future.
        Note: you need authentication to clone private repositories



        2.3 (optional) adding private permissions right



        cd ~/.ssh


        see if you have id_rsa.pub file. pub means public file and I recommend you just copy the whole content and paste to gitlab.com public ssh webpage.
        Done.
        You should not show others about corresponding file id_rsa, which is your key to access to gitlab repository. Other client/computer having id_rsa, with permission chmod 600 id_rsa, will be able to control repository.



        if you do not see id_rsa.pub, you could generate it using:



        ssh-keygen -t rsa


        Press enter to leave it default. Now you can see id_rsa.pub and id_rsa inside ~/.ssh directory. If you are using different name other than id_rsa by default, you should modify ~/.ssh/config file like this:



        # private account
        Host github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/github


        3. git-repo Usage



        as you're starting a new project, you want to create a new
        repository, out of GitLab, to push to:



        git lab create <username>/howto


        of course, you could delete, list repositories, or do other stuff.



        git lab delete <username>/howto
        git lab list <username>
        git lab clone <username>/howto
        git clone git@gitlab.com:<username>/howto





        Practical Example



        Assuming you have developed a local myproject directory with git committed for a while. Now you want to upload to GitLab.



        create remote repo in gitlab. You will see username/myproject in gitlab page.



        git lab create username/myproject


        Assuming there is a .git file under local myproject directory



        cd myproject


        link local directory to remote gitlab.com repo.



        git lab add username/myproject


        upload myproject directory to gitlab.com



        git push -u gitlab master


        done






        share|improve this answer

























          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33101962%2fhow-to-create-a-new-gitlab-repo-from-my-existing-local-git-repo-using-cli%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          47














          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






          share|improve this answer



















          • 6





            "Create new empty projects in GitLab" this was the question. I want to do it from CLI

            – Jitendra Vyas
            Oct 15 '15 at 12:05











          • maybe we should git remote remove origin first

            – MichaelMao
            Apr 24 '17 at 7:25
















          47














          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






          share|improve this answer



















          • 6





            "Create new empty projects in GitLab" this was the question. I want to do it from CLI

            – Jitendra Vyas
            Oct 15 '15 at 12:05











          • maybe we should git remote remove origin first

            – MichaelMao
            Apr 24 '17 at 7:25














          47












          47








          47







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 13 '15 at 17:36









          twk3twk3

          1,46387




          1,46387








          • 6





            "Create new empty projects in GitLab" this was the question. I want to do it from CLI

            – Jitendra Vyas
            Oct 15 '15 at 12:05











          • maybe we should git remote remove origin first

            – MichaelMao
            Apr 24 '17 at 7:25














          • 6





            "Create new empty projects in GitLab" this was the question. I want to do it from CLI

            – Jitendra Vyas
            Oct 15 '15 at 12:05











          • maybe we should git remote remove origin first

            – MichaelMao
            Apr 24 '17 at 7:25








          6




          6





          "Create new empty projects in GitLab" this was the question. I want to do it from CLI

          – Jitendra Vyas
          Oct 15 '15 at 12:05





          "Create new empty projects in GitLab" this was the question. I want to do it from CLI

          – Jitendra Vyas
          Oct 15 '15 at 12:05













          maybe we should git remote remove origin first

          – MichaelMao
          Apr 24 '17 at 7:25





          maybe we should git remote remove origin first

          – MichaelMao
          Apr 24 '17 at 7:25













          17














          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



          git push --set-upstream address/your-project.git


          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




          When you create a new repo locally, instead of going to GitLab to manually create a new project and then push the repo, you can directly push it to GitLab to create the new project, all without leaving your terminal. If you have access to that namespace, we 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 HTTP:




          ## Git push using SSH
          git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master

          ## Git push using HTTP
          git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master



          Once the push finishes successfully, a remote message will indicate the command to set the remote and the URL to the new project:




          remote:
          remote: The private project namespace/nonexistent-project was created.
          remote:
          remote: To configure the remote, run:
          remote: git remote add origin https://gitlab.example.com/namespace/nonexistent-project.git
          remote:
          remote: To view the project, visit:
          remote: https://gitlab.example.com/namespace/nonexistent-project
          remote:





          share|improve this answer






























            17














            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



            git push --set-upstream address/your-project.git


            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




            When you create a new repo locally, instead of going to GitLab to manually create a new project and then push the repo, you can directly push it to GitLab to create the new project, all without leaving your terminal. If you have access to that namespace, we 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 HTTP:




            ## Git push using SSH
            git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master

            ## Git push using HTTP
            git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master



            Once the push finishes successfully, a remote message will indicate the command to set the remote and the URL to the new project:




            remote:
            remote: The private project namespace/nonexistent-project was created.
            remote:
            remote: To configure the remote, run:
            remote: git remote add origin https://gitlab.example.com/namespace/nonexistent-project.git
            remote:
            remote: To view the project, visit:
            remote: https://gitlab.example.com/namespace/nonexistent-project
            remote:





            share|improve this answer




























              17












              17








              17







              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



              git push --set-upstream address/your-project.git


              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




              When you create a new repo locally, instead of going to GitLab to manually create a new project and then push the repo, you can directly push it to GitLab to create the new project, all without leaving your terminal. If you have access to that namespace, we 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 HTTP:




              ## Git push using SSH
              git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master

              ## Git push using HTTP
              git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master



              Once the push finishes successfully, a remote message will indicate the command to set the remote and the URL to the new project:




              remote:
              remote: The private project namespace/nonexistent-project was created.
              remote:
              remote: To configure the remote, run:
              remote: git remote add origin https://gitlab.example.com/namespace/nonexistent-project.git
              remote:
              remote: To view the project, visit:
              remote: https://gitlab.example.com/namespace/nonexistent-project
              remote:





              share|improve this answer















              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



              git push --set-upstream address/your-project.git


              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




              When you create a new repo locally, instead of going to GitLab to manually create a new project and then push the repo, you can directly push it to GitLab to create the new project, all without leaving your terminal. If you have access to that namespace, we 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 HTTP:




              ## Git push using SSH
              git push --set-upstream git@gitlab.example.com:namespace/nonexistent-project.git master

              ## Git push using HTTP
              git push --set-upstream https://gitlab.example.com/namespace/nonexistent-project.git master



              Once the push finishes successfully, a remote message will indicate the command to set the remote and the URL to the new project:




              remote:
              remote: The private project namespace/nonexistent-project was created.
              remote:
              remote: To configure the remote, run:
              remote: git remote add origin https://gitlab.example.com/namespace/nonexistent-project.git
              remote:
              remote: To view the project, visit:
              remote: https://gitlab.example.com/namespace/nonexistent-project
              remote:






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 14 '18 at 14:28

























              answered Mar 16 '18 at 9:43









              tedted

              2,51712049




              2,51712049























                  8














                  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:



                  $ sudo pip install python-gitlab


                  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:



                  [global]
                  # required setting
                  default = local
                  # optional settings
                  ssl_verify = false
                  timeout = 5

                  [local]
                  # url = http://10.0.3.2:8080
                  # get the private token from the gitlab web interface
                  # private_token = vTbFeqJYCY3sibBP7BZM

                  [remote]
                  url = YOUR SERVER URL GOES HERE
                  private_token = YOUR PRIVATE TOKEN GOES HERE
                  ssl_verify = false

                  [remote-ssl]
                  url = YOUR HTTPS URL GOES HERE (eg https://gitlab.ccompanyname.com))
                  private_token = YOUR PRIVATE TOKEN GOES HERE
                  ssl_verify = true (VALID CERTIFICATE) OR false (SELF-SIGNED CERTIFICATE)


                  You will have to get yourself a private token from the web interface (found in Profile Settings :: Account) since, as the README points out,




                  Only private token authentication is supported (not user/password).






                  After this is taken care of, creating a project can be achieved like this, for http:



                  $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote project create --name YOUR_PROJECT_NAME


                  and like this for https:



                  $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote-ssl project create --name YOUR_PROJECT_NAME




                  The switches used above, can be found by looking at the help:



                  $ gitlab --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:



                  #!/usr/bin/bash

                  cd 'PATH/TO/YOUR/REPOS/DIRECTORY' # enter your local repos dir here
                  server="YOUR SERVER" # enter your server URL
                  user="YOUR USER" # enter your user name
                  gitlab_cfg="PATH/TO/YOUR/.python-gitlab.cfg" # enter the location of config file
                  #method="remote" # uncomment for http, comment for https
                  method="remote-ssl" # uncomment for https, comment for http
                  for i in $( ls -1 ); do
                  echo
                  echo
                  echo '>> Creating Project'
                  gitlab -c $gitlab_cfg --gitlab $method project create --name $i
                  echo '>> Project ' $i 'created'
                  echo '>> ------'
                  cd $i
                  li=$( tr '[A-Z]' '[a-z]' <<< $i) # convert dirname to lowercase, safe with older bashes (<4)
                  origin="git@$server:$user/$li.git"
                  echo ">> Reassigning origin to : $origin"
                  git remote rm origin
                  git remote add origin $origin
                  git remote -v
                  echo '>> Pushing local repo to gitlab'
                  git push -u origin master
                  echo '>> Done'
                  echo
                  echo
                  cd ..
                  done
                  echo
                  echo 'Operation finished'


                  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 becomes samplerepo001 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:



                  enter image description here



                  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.






                  share|improve this answer






























                    8














                    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:



                    $ sudo pip install python-gitlab


                    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:



                    [global]
                    # required setting
                    default = local
                    # optional settings
                    ssl_verify = false
                    timeout = 5

                    [local]
                    # url = http://10.0.3.2:8080
                    # get the private token from the gitlab web interface
                    # private_token = vTbFeqJYCY3sibBP7BZM

                    [remote]
                    url = YOUR SERVER URL GOES HERE
                    private_token = YOUR PRIVATE TOKEN GOES HERE
                    ssl_verify = false

                    [remote-ssl]
                    url = YOUR HTTPS URL GOES HERE (eg https://gitlab.ccompanyname.com))
                    private_token = YOUR PRIVATE TOKEN GOES HERE
                    ssl_verify = true (VALID CERTIFICATE) OR false (SELF-SIGNED CERTIFICATE)


                    You will have to get yourself a private token from the web interface (found in Profile Settings :: Account) since, as the README points out,




                    Only private token authentication is supported (not user/password).






                    After this is taken care of, creating a project can be achieved like this, for http:



                    $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote project create --name YOUR_PROJECT_NAME


                    and like this for https:



                    $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote-ssl project create --name YOUR_PROJECT_NAME




                    The switches used above, can be found by looking at the help:



                    $ gitlab --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:



                    #!/usr/bin/bash

                    cd 'PATH/TO/YOUR/REPOS/DIRECTORY' # enter your local repos dir here
                    server="YOUR SERVER" # enter your server URL
                    user="YOUR USER" # enter your user name
                    gitlab_cfg="PATH/TO/YOUR/.python-gitlab.cfg" # enter the location of config file
                    #method="remote" # uncomment for http, comment for https
                    method="remote-ssl" # uncomment for https, comment for http
                    for i in $( ls -1 ); do
                    echo
                    echo
                    echo '>> Creating Project'
                    gitlab -c $gitlab_cfg --gitlab $method project create --name $i
                    echo '>> Project ' $i 'created'
                    echo '>> ------'
                    cd $i
                    li=$( tr '[A-Z]' '[a-z]' <<< $i) # convert dirname to lowercase, safe with older bashes (<4)
                    origin="git@$server:$user/$li.git"
                    echo ">> Reassigning origin to : $origin"
                    git remote rm origin
                    git remote add origin $origin
                    git remote -v
                    echo '>> Pushing local repo to gitlab'
                    git push -u origin master
                    echo '>> Done'
                    echo
                    echo
                    cd ..
                    done
                    echo
                    echo 'Operation finished'


                    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 becomes samplerepo001 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:



                    enter image description here



                    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.






                    share|improve this answer




























                      8












                      8








                      8







                      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:



                      $ sudo pip install python-gitlab


                      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:



                      [global]
                      # required setting
                      default = local
                      # optional settings
                      ssl_verify = false
                      timeout = 5

                      [local]
                      # url = http://10.0.3.2:8080
                      # get the private token from the gitlab web interface
                      # private_token = vTbFeqJYCY3sibBP7BZM

                      [remote]
                      url = YOUR SERVER URL GOES HERE
                      private_token = YOUR PRIVATE TOKEN GOES HERE
                      ssl_verify = false

                      [remote-ssl]
                      url = YOUR HTTPS URL GOES HERE (eg https://gitlab.ccompanyname.com))
                      private_token = YOUR PRIVATE TOKEN GOES HERE
                      ssl_verify = true (VALID CERTIFICATE) OR false (SELF-SIGNED CERTIFICATE)


                      You will have to get yourself a private token from the web interface (found in Profile Settings :: Account) since, as the README points out,




                      Only private token authentication is supported (not user/password).






                      After this is taken care of, creating a project can be achieved like this, for http:



                      $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote project create --name YOUR_PROJECT_NAME


                      and like this for https:



                      $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote-ssl project create --name YOUR_PROJECT_NAME




                      The switches used above, can be found by looking at the help:



                      $ gitlab --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:



                      #!/usr/bin/bash

                      cd 'PATH/TO/YOUR/REPOS/DIRECTORY' # enter your local repos dir here
                      server="YOUR SERVER" # enter your server URL
                      user="YOUR USER" # enter your user name
                      gitlab_cfg="PATH/TO/YOUR/.python-gitlab.cfg" # enter the location of config file
                      #method="remote" # uncomment for http, comment for https
                      method="remote-ssl" # uncomment for https, comment for http
                      for i in $( ls -1 ); do
                      echo
                      echo
                      echo '>> Creating Project'
                      gitlab -c $gitlab_cfg --gitlab $method project create --name $i
                      echo '>> Project ' $i 'created'
                      echo '>> ------'
                      cd $i
                      li=$( tr '[A-Z]' '[a-z]' <<< $i) # convert dirname to lowercase, safe with older bashes (<4)
                      origin="git@$server:$user/$li.git"
                      echo ">> Reassigning origin to : $origin"
                      git remote rm origin
                      git remote add origin $origin
                      git remote -v
                      echo '>> Pushing local repo to gitlab'
                      git push -u origin master
                      echo '>> Done'
                      echo
                      echo
                      cd ..
                      done
                      echo
                      echo 'Operation finished'


                      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 becomes samplerepo001 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:



                      enter image description here



                      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.






                      share|improve this answer















                      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:



                      $ sudo pip install python-gitlab


                      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:



                      [global]
                      # required setting
                      default = local
                      # optional settings
                      ssl_verify = false
                      timeout = 5

                      [local]
                      # url = http://10.0.3.2:8080
                      # get the private token from the gitlab web interface
                      # private_token = vTbFeqJYCY3sibBP7BZM

                      [remote]
                      url = YOUR SERVER URL GOES HERE
                      private_token = YOUR PRIVATE TOKEN GOES HERE
                      ssl_verify = false

                      [remote-ssl]
                      url = YOUR HTTPS URL GOES HERE (eg https://gitlab.ccompanyname.com))
                      private_token = YOUR PRIVATE TOKEN GOES HERE
                      ssl_verify = true (VALID CERTIFICATE) OR false (SELF-SIGNED CERTIFICATE)


                      You will have to get yourself a private token from the web interface (found in Profile Settings :: Account) since, as the README points out,




                      Only private token authentication is supported (not user/password).






                      After this is taken care of, creating a project can be achieved like this, for http:



                      $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote project create --name YOUR_PROJECT_NAME


                      and like this for https:



                      $ gitlab -c "PATH/TO/YOUR/.python-gitlab.cfg" --gitlab remote-ssl project create --name YOUR_PROJECT_NAME




                      The switches used above, can be found by looking at the help:



                      $ gitlab --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:



                      #!/usr/bin/bash

                      cd 'PATH/TO/YOUR/REPOS/DIRECTORY' # enter your local repos dir here
                      server="YOUR SERVER" # enter your server URL
                      user="YOUR USER" # enter your user name
                      gitlab_cfg="PATH/TO/YOUR/.python-gitlab.cfg" # enter the location of config file
                      #method="remote" # uncomment for http, comment for https
                      method="remote-ssl" # uncomment for https, comment for http
                      for i in $( ls -1 ); do
                      echo
                      echo
                      echo '>> Creating Project'
                      gitlab -c $gitlab_cfg --gitlab $method project create --name $i
                      echo '>> Project ' $i 'created'
                      echo '>> ------'
                      cd $i
                      li=$( tr '[A-Z]' '[a-z]' <<< $i) # convert dirname to lowercase, safe with older bashes (<4)
                      origin="git@$server:$user/$li.git"
                      echo ">> Reassigning origin to : $origin"
                      git remote rm origin
                      git remote add origin $origin
                      git remote -v
                      echo '>> Pushing local repo to gitlab'
                      git push -u origin master
                      echo '>> Done'
                      echo
                      echo
                      cd ..
                      done
                      echo
                      echo 'Operation finished'


                      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 becomes samplerepo001 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:



                      enter image description here



                      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.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Oct 16 '15 at 21:32

























                      answered Oct 15 '15 at 18:01









                      sokinsokin

                      74421219




                      74421219























                          1














                          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:




                          • Use API to create project on gitlab.com

                          • git remote add gitlab url-to-gitlab-repo

                          • git push gitlab --mirror






                          share|improve this answer






























                            1














                            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:




                            • Use API to create project on gitlab.com

                            • git remote add gitlab url-to-gitlab-repo

                            • git push gitlab --mirror






                            share|improve this answer




























                              1












                              1








                              1







                              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:




                              • Use API to create project on gitlab.com

                              • git remote add gitlab url-to-gitlab-repo

                              • git push gitlab --mirror






                              share|improve this answer















                              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:




                              • Use API to create project on gitlab.com

                              • git remote add gitlab url-to-gitlab-repo

                              • git push gitlab --mirror







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jun 30 '16 at 23:34

























                              answered Jun 30 '16 at 23:15









                              user3606666user3606666

                              112




                              112























                                  0














                                  git-repo has done the dirty jobs for you. It also supports GitLab, GitHub and Bitbucket.



                                  1. Installation



                                  apt-get install python-pip
                                  pip install git-repo


                                  you might need pip3 if the above command is not working.



                                  (optional)
                                  apt-get install python3-pip
                                  pip3 install git-repo


                                  2 Configuration



                                  2.1 necessary configuration



                                  git repo config


                                  The command line tool, step by step, will ask if you want to set up bitbucket, github, gitlab account, press 'y/n' and username/password accordingly. If you do not know what it means, press 'n' to skip. The configuration file will be generated in ~/.gitconfig. You may want to tweak it afterwards.



                                  (optional) for example, you could manually set token in ~/.gitconfig like this:



                                  [gitrepo "gitlab"]
                                  token = xxxxxxx
                                  [gitrepo "github"]
                                  token = xxxxxxx


                                  2.2 better shortcut



                                  append following lines to ~/.gitconfig.



                                  [alias]
                                  hub = repo hub
                                  lab = repo lab


                                  why?



                                  Because now you could simply use shortcut
                                  git lab clone /howto
                                  git hub clone /howto
                                  in the future.
                                  Note: you need authentication to clone private repositories



                                  2.3 (optional) adding private permissions right



                                  cd ~/.ssh


                                  see if you have id_rsa.pub file. pub means public file and I recommend you just copy the whole content and paste to gitlab.com public ssh webpage.
                                  Done.
                                  You should not show others about corresponding file id_rsa, which is your key to access to gitlab repository. Other client/computer having id_rsa, with permission chmod 600 id_rsa, will be able to control repository.



                                  if you do not see id_rsa.pub, you could generate it using:



                                  ssh-keygen -t rsa


                                  Press enter to leave it default. Now you can see id_rsa.pub and id_rsa inside ~/.ssh directory. If you are using different name other than id_rsa by default, you should modify ~/.ssh/config file like this:



                                  # private account
                                  Host github.com
                                  PreferredAuthentications publickey
                                  IdentityFile ~/.ssh/github


                                  3. git-repo Usage



                                  as you're starting a new project, you want to create a new
                                  repository, out of GitLab, to push to:



                                  git lab create <username>/howto


                                  of course, you could delete, list repositories, or do other stuff.



                                  git lab delete <username>/howto
                                  git lab list <username>
                                  git lab clone <username>/howto
                                  git clone git@gitlab.com:<username>/howto





                                  Practical Example



                                  Assuming you have developed a local myproject directory with git committed for a while. Now you want to upload to GitLab.



                                  create remote repo in gitlab. You will see username/myproject in gitlab page.



                                  git lab create username/myproject


                                  Assuming there is a .git file under local myproject directory



                                  cd myproject


                                  link local directory to remote gitlab.com repo.



                                  git lab add username/myproject


                                  upload myproject directory to gitlab.com



                                  git push -u gitlab master


                                  done






                                  share|improve this answer






























                                    0














                                    git-repo has done the dirty jobs for you. It also supports GitLab, GitHub and Bitbucket.



                                    1. Installation



                                    apt-get install python-pip
                                    pip install git-repo


                                    you might need pip3 if the above command is not working.



                                    (optional)
                                    apt-get install python3-pip
                                    pip3 install git-repo


                                    2 Configuration



                                    2.1 necessary configuration



                                    git repo config


                                    The command line tool, step by step, will ask if you want to set up bitbucket, github, gitlab account, press 'y/n' and username/password accordingly. If you do not know what it means, press 'n' to skip. The configuration file will be generated in ~/.gitconfig. You may want to tweak it afterwards.



                                    (optional) for example, you could manually set token in ~/.gitconfig like this:



                                    [gitrepo "gitlab"]
                                    token = xxxxxxx
                                    [gitrepo "github"]
                                    token = xxxxxxx


                                    2.2 better shortcut



                                    append following lines to ~/.gitconfig.



                                    [alias]
                                    hub = repo hub
                                    lab = repo lab


                                    why?



                                    Because now you could simply use shortcut
                                    git lab clone /howto
                                    git hub clone /howto
                                    in the future.
                                    Note: you need authentication to clone private repositories



                                    2.3 (optional) adding private permissions right



                                    cd ~/.ssh


                                    see if you have id_rsa.pub file. pub means public file and I recommend you just copy the whole content and paste to gitlab.com public ssh webpage.
                                    Done.
                                    You should not show others about corresponding file id_rsa, which is your key to access to gitlab repository. Other client/computer having id_rsa, with permission chmod 600 id_rsa, will be able to control repository.



                                    if you do not see id_rsa.pub, you could generate it using:



                                    ssh-keygen -t rsa


                                    Press enter to leave it default. Now you can see id_rsa.pub and id_rsa inside ~/.ssh directory. If you are using different name other than id_rsa by default, you should modify ~/.ssh/config file like this:



                                    # private account
                                    Host github.com
                                    PreferredAuthentications publickey
                                    IdentityFile ~/.ssh/github


                                    3. git-repo Usage



                                    as you're starting a new project, you want to create a new
                                    repository, out of GitLab, to push to:



                                    git lab create <username>/howto


                                    of course, you could delete, list repositories, or do other stuff.



                                    git lab delete <username>/howto
                                    git lab list <username>
                                    git lab clone <username>/howto
                                    git clone git@gitlab.com:<username>/howto





                                    Practical Example



                                    Assuming you have developed a local myproject directory with git committed for a while. Now you want to upload to GitLab.



                                    create remote repo in gitlab. You will see username/myproject in gitlab page.



                                    git lab create username/myproject


                                    Assuming there is a .git file under local myproject directory



                                    cd myproject


                                    link local directory to remote gitlab.com repo.



                                    git lab add username/myproject


                                    upload myproject directory to gitlab.com



                                    git push -u gitlab master


                                    done






                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      git-repo has done the dirty jobs for you. It also supports GitLab, GitHub and Bitbucket.



                                      1. Installation



                                      apt-get install python-pip
                                      pip install git-repo


                                      you might need pip3 if the above command is not working.



                                      (optional)
                                      apt-get install python3-pip
                                      pip3 install git-repo


                                      2 Configuration



                                      2.1 necessary configuration



                                      git repo config


                                      The command line tool, step by step, will ask if you want to set up bitbucket, github, gitlab account, press 'y/n' and username/password accordingly. If you do not know what it means, press 'n' to skip. The configuration file will be generated in ~/.gitconfig. You may want to tweak it afterwards.



                                      (optional) for example, you could manually set token in ~/.gitconfig like this:



                                      [gitrepo "gitlab"]
                                      token = xxxxxxx
                                      [gitrepo "github"]
                                      token = xxxxxxx


                                      2.2 better shortcut



                                      append following lines to ~/.gitconfig.



                                      [alias]
                                      hub = repo hub
                                      lab = repo lab


                                      why?



                                      Because now you could simply use shortcut
                                      git lab clone /howto
                                      git hub clone /howto
                                      in the future.
                                      Note: you need authentication to clone private repositories



                                      2.3 (optional) adding private permissions right



                                      cd ~/.ssh


                                      see if you have id_rsa.pub file. pub means public file and I recommend you just copy the whole content and paste to gitlab.com public ssh webpage.
                                      Done.
                                      You should not show others about corresponding file id_rsa, which is your key to access to gitlab repository. Other client/computer having id_rsa, with permission chmod 600 id_rsa, will be able to control repository.



                                      if you do not see id_rsa.pub, you could generate it using:



                                      ssh-keygen -t rsa


                                      Press enter to leave it default. Now you can see id_rsa.pub and id_rsa inside ~/.ssh directory. If you are using different name other than id_rsa by default, you should modify ~/.ssh/config file like this:



                                      # private account
                                      Host github.com
                                      PreferredAuthentications publickey
                                      IdentityFile ~/.ssh/github


                                      3. git-repo Usage



                                      as you're starting a new project, you want to create a new
                                      repository, out of GitLab, to push to:



                                      git lab create <username>/howto


                                      of course, you could delete, list repositories, or do other stuff.



                                      git lab delete <username>/howto
                                      git lab list <username>
                                      git lab clone <username>/howto
                                      git clone git@gitlab.com:<username>/howto





                                      Practical Example



                                      Assuming you have developed a local myproject directory with git committed for a while. Now you want to upload to GitLab.



                                      create remote repo in gitlab. You will see username/myproject in gitlab page.



                                      git lab create username/myproject


                                      Assuming there is a .git file under local myproject directory



                                      cd myproject


                                      link local directory to remote gitlab.com repo.



                                      git lab add username/myproject


                                      upload myproject directory to gitlab.com



                                      git push -u gitlab master


                                      done






                                      share|improve this answer















                                      git-repo has done the dirty jobs for you. It also supports GitLab, GitHub and Bitbucket.



                                      1. Installation



                                      apt-get install python-pip
                                      pip install git-repo


                                      you might need pip3 if the above command is not working.



                                      (optional)
                                      apt-get install python3-pip
                                      pip3 install git-repo


                                      2 Configuration



                                      2.1 necessary configuration



                                      git repo config


                                      The command line tool, step by step, will ask if you want to set up bitbucket, github, gitlab account, press 'y/n' and username/password accordingly. If you do not know what it means, press 'n' to skip. The configuration file will be generated in ~/.gitconfig. You may want to tweak it afterwards.



                                      (optional) for example, you could manually set token in ~/.gitconfig like this:



                                      [gitrepo "gitlab"]
                                      token = xxxxxxx
                                      [gitrepo "github"]
                                      token = xxxxxxx


                                      2.2 better shortcut



                                      append following lines to ~/.gitconfig.



                                      [alias]
                                      hub = repo hub
                                      lab = repo lab


                                      why?



                                      Because now you could simply use shortcut
                                      git lab clone /howto
                                      git hub clone /howto
                                      in the future.
                                      Note: you need authentication to clone private repositories



                                      2.3 (optional) adding private permissions right



                                      cd ~/.ssh


                                      see if you have id_rsa.pub file. pub means public file and I recommend you just copy the whole content and paste to gitlab.com public ssh webpage.
                                      Done.
                                      You should not show others about corresponding file id_rsa, which is your key to access to gitlab repository. Other client/computer having id_rsa, with permission chmod 600 id_rsa, will be able to control repository.



                                      if you do not see id_rsa.pub, you could generate it using:



                                      ssh-keygen -t rsa


                                      Press enter to leave it default. Now you can see id_rsa.pub and id_rsa inside ~/.ssh directory. If you are using different name other than id_rsa by default, you should modify ~/.ssh/config file like this:



                                      # private account
                                      Host github.com
                                      PreferredAuthentications publickey
                                      IdentityFile ~/.ssh/github


                                      3. git-repo Usage



                                      as you're starting a new project, you want to create a new
                                      repository, out of GitLab, to push to:



                                      git lab create <username>/howto


                                      of course, you could delete, list repositories, or do other stuff.



                                      git lab delete <username>/howto
                                      git lab list <username>
                                      git lab clone <username>/howto
                                      git clone git@gitlab.com:<username>/howto





                                      Practical Example



                                      Assuming you have developed a local myproject directory with git committed for a while. Now you want to upload to GitLab.



                                      create remote repo in gitlab. You will see username/myproject in gitlab page.



                                      git lab create username/myproject


                                      Assuming there is a .git file under local myproject directory



                                      cd myproject


                                      link local directory to remote gitlab.com repo.



                                      git lab add username/myproject


                                      upload myproject directory to gitlab.com



                                      git push -u gitlab master


                                      done







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Apr 18 '17 at 10:48

























                                      answered Feb 18 '17 at 6:04









                                      anonymousanonymous

                                      475611




                                      475611






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33101962%2fhow-to-create-a-new-gitlab-repo-from-my-existing-local-git-repo-using-cli%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Bressuire

                                          Vorschmack

                                          Quarantine