Files
ghorg/examples/gitlab.md
2023-01-01 07:56:05 -08:00

4.1 KiB

GitLab Examples

Note: all command line arguments can be permanently set in your $HOME/.config/ghorg/conf.yaml for more information see the configuration section of the README.md.

To view all additional flags see the sample-conf.yaml or use ghorg clone --help

Things to know

  1. There are differences in how ghorg works with GitLab on hosted instances vs GitLab cloud. Please make sure to follow the correct section below.

  2. With GitLab, if ghorg detects repo naming collisions with repos being cloned from different groups/subgroups, ghorg will automatically append the group/subgroup path to the repo name. You will be notified in the output if this occurs.

  3. For all versions of GitLab you can clone groups or sub groups individually

  4. The --preserve-dir flag will mirror the nested directory structure of the groups/subgroups/projects locally to what is on GitLab. This prevents any name collisions with project names. If this flag is ommited all projects will be cloned into a single directory. If there are collisions with project names and --preserve-dir is not used the group/subgroup name will be prepended to those projects. An informational message will also be displayed during the clone to let you know if this happens.

Hosted GitLab Instances

Cloning All Groups

Note: "all-groups" only works on hosted GitLab instances running 13.0.1 or greater

Note: You must set --base-url which is the url to your instance. If your instance requires an insecure connection you can use the --insecure-gitlab-client flag

  1. Clone all groups preserving the directory structure of subgroups

    ghorg clone all-groups --base-url=https://<your.instance.gitlab.com> --scm=gitlab --token=XXXXXX --preserve-dir
    
  2. Clone all groups on an insecure instance preserving the directory structure of subgroups

    ghorg clone all-groups --base-url=http://<your.instance.gitlab.com> --scm=gitlab --token=XXXXXX --preserve-dir --insecure-gitlab-client
    

Cloning Specific Groups

  1. Clone a single group, preserving the directory structure of any subgroups within that group

    ghorg clone <gitlab_group> --base-url=https://<your.instance.gitlab.com> --scm=gitlab --preserve-dir
    
  2. Clone only a subgroup

    ghorg clone <gitlab_group>/<gitlab_sub_group> --base-url=https://<your.instance.gitlab.com> --scm=gitlab
    
  3. clone all repos that are prefixed with "frontend" into a folder called "design_only"

    ghorg clone <gitlab_group> --base-url=https://<your.instance.gitlab.com> --scm=gitlab --match-regex=^frontend --output-dir=design_only
    

Cloning a Specific Users Repos

  1. Clone a user on a hosted gitlab instance using a token for auth

    ghorg clone <gitlab_username> --clone-type=user --base-url=https://<your.instance.gitlab.com> --scm=gitlab --token=bGVhdmUgYSBjb21tZW50IG9uIGlzc3VlIDY2
    

Cloning All Users Repos

Note: "all-users" only works on hosted GitLab instances running 13.0.1 or greater

Note: You must set --base-url which is the url to your instance. If your instance requires an insecure connection you can use the --insecure-gitlab-client flag

  1. Clone all users repos into a directory called all-users-repos

    ghorg clone all-users --base-url=https://<your.instance.gitlab.com> --scm=gitlab --token=XXXXXX --clone-type=user --output-dir=all-users-repos
    
  2. Clone all users repos on an insecure instance

    ghorg clone all-users --base-url=http://<your.instance.gitlab.com> --scm=gitlab --token=XXXXXX --clone-type=user --insecure-gitlab-client
    
    

Cloud GitLab Orgs

Examples below use the gitlab-examples GitLab cloud organization https://gitlab.com/gitlab-examples

  1. clone all groups, preserving the directory structure of subgroups

    ghorg clone gitlab-examples --scm=gitlab --token=XXXXXX --preserve-dir
    
  2. clone only a subgroup

    ghorg clone gitlab-examples/wayne-enterprises --scm=gitlab --token=XXXXXX