From Ever changing code

< Git

Download all repositories

Gitlab server

Note: Pending update 2020, to distinguish all repos vs private to view as it's a difference when hosting on and your own server where 'public' repos are still private to you. This is not a case for You can get token when log in to your account > settings and generate access token. Assign all permissions. Also so you know v3 APIs may be deployed on older version Gitlab.


# Get pages count of all repos you can access
# $ curl --head "http://<>/api/v4/projects?private_token=<token>=100&page=1" | grep Total
#   X-Total: 509
#   X-Total-Pages: 6

#Create JSON file with repo name and path
#for PAGE in {1..6}; do curl "<>/api/v4/projects?private_token=CMQdz-Qik8XanGYJTbnH&per_page=100&page=$PAGE" | jq --raw-output --compact-output ".[] | { "path": .path, "git": .ssh_url_to_repo }" >> repos.json; done

[ -d repos ] || mkdir repos
cd repos
while read repo; do
    THEPATH=$(echo "$repo" | jq -r ".path")
    echo "path: $THEPATH"
    GIT=$(echo "$repo" | jq -r ".git")
    echo "git: $GIT"

    if [ ! -d "$THEPATH" ]; then
        echo "Cloning $THEPATH ( $GIT )"
        git clone "$GIT"
        echo "Pulling $THEPATH"
        (cd "$THEPATH" && git pull)
done < "../$FILENAME"
cd ..

Example repos.json

{"path":"project-y","git":"git@<>:Spikes/AWS/project-y.git"} (SaaS)

Download all private repositories from a given group. Tested on Sep-2021.

GROUP_ID=1234567${GROUP_NAME}-$(date +"%Y%m%d-%H%M").json
curl -s --header "PRIVATE-TOKEN: ${PAT}"${GROUP_ID} | jq . > $FILE
for repo in $(cat  $FILE | jq ".projects[].ssh_url_to_repo" | tr -d '"'); do git clone $repo; done;

Gitlab - glab cli

glab - work seamlessly with Gitlab from the command line inspired by Github gh tool.
$ glab auth login
? What GitLab instance do you want to log into?
- Logging into

Tip: you can generate a Personal Access Token here
The minimum required scopes are 'api' and 'write_repository'.
? Paste your authentication token: ********************
? Choose default git protocol HTTPS
? Authenticate Git with your GitLab credentials? Yes
- glab config set -h git_protocol https
✓ Configured git protocol
- glab config set -h api_protocol https
✓ Configured API protocol
✓ Logged in as piotr

# cd to repo, so the tool knows which remote project talk to
glab mr view   <merge_request_id>
glab mr accept <merge_request_id>
glab mr merge  <merge_request_id>

# Create MR using git only. The title is the last commit message eg. JIRA-1234: Update README
git push --set-upstream origin mybranch -o merge_request.create

Reset a user password

This could be also root user.

ubuntu@gitlab:~$  sudo gitlab-rails console
 GitLab:       11.4.0 (6ebbd70)
 GitLab Shell: 8.3.3
 postgresql:   9.6.8
Loading production environment (Rails 4.2.10)
irb(main):001:0> user = User.find_by(username: "bob")
                 user = User.find_by(id: 1)    //by id
=> #<User id:5 @bob>
irb(main):002:0> user.password = 'test1234'    //at least 8 characters long
=> "test1"
irb(main):003:0> user.password_confirmation = 'test1234'
=> "test1"
irb(main):007:0> user.unlock_access!
=> true
=> false

Deployment token

In course to grant access to a single repository for reading, writting or both we can use feature called Deploy Tokens. Go to repository > repository settings > Deploy Tokens to create one.


Access repository

# Syntax
# git clone http://<username>:<deploy_token>

# Example
git clone
Cloning into 'apache-nginx-ssl'...
remote: Enumerating objects: 110, done.
remote: Counting objects: 100% (110/110), done.

GitLab CI