Skip to content

Instantly share code, notes, and snippets.

@gijun19
Last active July 16, 2020 01:14
Show Gist options
  • Save gijun19/8f6756e56ed6b3209574293c227c3f50 to your computer and use it in GitHub Desktop.
Save gijun19/8f6756e56ed6b3209574293c227c3f50 to your computer and use it in GitHub Desktop.
GitLab token clone helper.
export PAT="$PAT_OR_TOKEN"
export USER="$USER_NAME"
function gcpat {
substring=$(echo "$1" | sed -e 's/https:\/\///g')
url=https://"$USER":"$PAT"@"$substring"
git clone "$url"
}
@gijun19
Copy link
Author

gijun19 commented Jun 30, 2020

Overview

This snippet enables a function called gcpat which will automatically format a HTTPS GitLab url to its token counterpart.

How to use

If you use zsh you will need to edit .zshrc, if you use bash edit .bashrc, any others edit the respective configuration file.

Just copy and paste the following into the file and replace the NGK variables with your values. This could either be an OAuth token or just a regular PAT from GitLab.

export PAT="random_access_token" # Insert your token here
export USER="gitlab_username" # If you're using OAuth, the username would be 'oauth', otherwise use your GitLab username.

Then either restart your terminal or use source ${path/to/bash_config}.

source ~/.zshrc

Then you can just grab any HTTPS url from the GitLab UI and call the function from your terminal.

gcpat {httpGitLabUrl}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment