Store username and password

Hi there

I have an account on Gitlab server( it’s NOT on my own VPS).

When I ran clone or push commands a prompt ask me for my Gitlab user name and password!

How can I store my Gitlab user name and password? I don’t want ask me every time I ran those commands.

Any helps would be appreciated.

You can set your username using the command:

git config --global user.name "<username goes here>"

To set your password, add the following line to your ~/.bashrc (or whatever file runs when you start your terminal):

export GIT_ASKPASS="<password goes here>"

What this does is set the environment variable GIT_ASKPASS to your password. When git looks for a password, it will see that you have the GIT_ASKPASS set, so it will not prompt you.

Note this works for any git host, not just GitLab :slight_smile:

2 Likes

Hi

Please add SSH key to your GitLab account.

3 Likes

Do not do what @thepiercingarrow has suggested and put your password in plain text in .bashrc. This is a terrible idea. I might look convenient but this is how accounts get compromised. Follow the link from @ershad.ahmad, an SSH key pair is easy to set up and more convenient in the long run.

Rip me D: yea sorry.

Does this work when using http as the GitLab protocol?

No, it doesn’t. It works only if you are using ssh (git@…).

thanks

And what if the remote url is like http://192.168.2.102:8929/foo/bar.git

You can’t tell from the url what protocol is actually supposed to be used.

If it’s SSH add an SSH key as @ershad.ahmad said and configure that host in your SSH config (in Linux/FreeBSD/… it’s in ~/.ssh/config.

1 Like