2551

I want to use a push and pull automatically in Git Extensions, Sourcetree or any other Git GUI without entering my username and password in a prompt, every time.

So how can I save my credentials in Git?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Edson Cezar
  • 25,884
  • 5
  • 19
  • 27
  • 22
    You can also authenticate via SSH: https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password – Anton Tarasenko Nov 12 '19 at 00:12
  • 2
    Also see [Is there a way to cache GitHub credentials for pushing commits?](https://stackoverflow.com/q/5343068/608639) and [Configuring user and password with Git Bash](https://stackoverflow.com/q/8840551/608639). – jww Nov 12 '19 at 20:49
  • 2
    As far as GitHub, the current policy (as of Aug 2021) is that you can *NO LONGER* have username/passwords. Instead, you *MUST* use SSH or "Personal Access tokens": [Dealing With GitHub Password Authentication Deprecation](https://betterprogramming.pub/dealing-with-github-password-authentication-deprecation-1b59ced90065) – paulsm4 Sep 14 '21 at 03:38
  • 2
    @paulsm4 A secure user-friendly alternative to SSH or personal access tokens is OAuth via Git Credential Manager, see my answer https://stackoverflow.com/a/71284566/284795 – Colonel Panic Feb 27 '22 at 16:35
  • 1
    See also this [2022 Git mailing list thread](https://public-inbox.org/git/Y2rdw7RD8mGTF40w@tapette.crustytoothpaste.net/T/#u). – VonC Nov 09 '22 at 19:01

33 Answers33

4164

Attention: This method saves the credentials in plaintext on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.

Run

git config --global credential.helper store

then

git pull

provide a username and password and those details will then be remembered later. The credentials are stored in a file on the disk, with the disk permissions of "just user readable/writable" but still in plaintext.

If you want to change the password later

git pull

Will fail, because the password is incorrect, git then removes the offending user+password from the ~/.git-credentials file, so now re-run

git pull

to provide a new password so it works as earlier.

Dominik
  • 2,283
  • 1
  • 25
  • 37
Neetika
  • 41,966
  • 1
  • 11
  • 7
  • 27
    for Debian/Ubuntu use libsecret https://stackoverflow.com/questions/36585496/error-when-using-git-credential-helper-with-gnome-keyring-as-sudo/40312117#40312117 – rofrol Oct 02 '17 at 14:29
  • 208
    Note that this will store your username and password in a plain text file at ~/.git-credentials. Anyone can open it and read it. – RoboAlex Sep 24 '18 at 04:13
  • 1
    It only works for one repository, the repo you are currently in. If I want to work with another repo, I need to do that again – Shamsul Arefin Jan 20 '19 at 11:42
  • 3
    @ShamsulArefinSajib Use `git config --global ...` – Sean Allred Jan 22 '19 at 00:52
  • 1
    `store` is unsafe, and if my machine gets stolen? I would be doomed..., should be `cache` – Aquarius Power Jan 23 '19 at 04:21
  • 13
    and use this if you want to forget : git config --global credential.helper forget – jacktrade Oct 23 '19 at 10:22
  • 43
    I think it's worth pointing out that one may want to skip the `--global` to only store the password for one repository (when pulling and pushing) but not for any other repository (which might be on a different hoster, with different credentials that one might not want to store for whatever reasons) – pseyfert Nov 26 '19 at 10:04
  • 1
    @RoboAlex If you are on Linux, the file is protected and can only be read by you. So yes, there is a file, but no, noone except for you can read it. (I don't know about Windows, though.) – vauhochzett Jan 07 '20 at 20:37
  • how can I use this for gitlab @Neetika – anil Feb 28 '20 at 07:23
  • 1
    I work with 2 different repositories(office + personal) with different usernames/passwords. Can I save 2 usernames/passwords with different repositories? If yes then how? – Pradeep Singh Mar 08 '20 at 18:21
  • Note that you can create an oauth-token and use that instead of your GitHub password. This slightly improves security, since anyone with the token can still access your repos, but cannot access your GitHub account (through a browser). – AstroFloyd May 20 '20 at 12:50
  • 2
    If using Gitlab or Github, you can create an access token in your account settings, and provide this token instead of your password. The token will be saved in the ~/.git-credentials file instead of your password and can be easily revoked from your account settings. – Mathieu Rollet Feb 17 '21 at 09:22
  • 57
    @RoboAlex's comment is popular but the protections on `~/.git-credentials` are no different than a private key like `~/.ssh/id_rsa`. So if you don't have a password on your private key then `~/git-credentials` is no worse than ssh keys – Jason S Mar 19 '21 at 13:05
  • [stack answer](https://askubuntu.com/a/959662/443958) shows a stellar way to easily encrypt the token/password in 3 simple steps. – agent18 May 02 '21 at 20:05
  • 1
    It's stored in memory, not on disk: https://git-scm.com/docs/git-credential-cache @RoboAlex take notice pls. – mirekphd Jun 20 '21 at 10:54
  • why does git not just encrypt the storage file? – Zapnologica Jul 08 '21 at 04:21
  • what about Ubuntu WSL on Windows? Is this also plain-text readable due to Windows at the base? – runr May 06 '22 at 16:51
  • 1
    @AquariusPower if your machine gets stolen, you login to GH from a different location and delete the key and generate a new one. Then the thief only can learn your username, which is public information already. (Assuming the thief can login to the machine) – REMCodes Jul 10 '22 at 16:02
  • @REMCodes and if I learn about the theft only after I come back from a travel? `cache` is overall better – Aquarius Power Jul 11 '22 at 20:46
  • @PradeepSingh If you want to switch to another account, you may need to check this thread: https://stackoverflow.com/a/48970546/264052, which essentially disables the credential store. After all, just manipulate the `.gitconfig` file to your purpose. – smwikipedia Sep 05 '22 at 05:57
  • it is possible to revoke remember u.name and pwd? – CodeBy Jan 18 '23 at 21:20
  • it is possible save only for specific repo? – CodeBy Jan 18 '23 at 21:22
636

You can use the git config to enable credentials storage in Git.

git config --global credential.helper store

When running this command, the first time you pull or push from the remote repository, you'll get asked about the username and password.

Afterwards, for consequent communications with the remote repository you don't have to provide the username and password.

The storage format is a .git-credentials file, stored in plaintext.

Also, you can use other helpers for the git config credential.helper, namely memory cache:

git config credential.helper 'cache --timeout=<timeout>'

which takes an optional timeout parameter, determining for how long the credentials will be kept in memory. Using the helper, the credentials will never touch the disk and will be erased after the specified timeout. The default value is 900 seconds (15 minutes).


Warning: If you use this method, your Git account passwords will be saved in plaintext format, in the global .gitconfig file, e.g in Linux it will be /home/[username]/.gitconfig.

If this is undesirable to you, use an ssh key for your accounts instead.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Farhad
  • 12,178
  • 5
  • 32
  • 60
  • 3
    Wish you showed the .gitconfig file - the first command has been overwritten by the second :( – Adam Mar 08 '17 at 13:24
  • 16
    For `git config credential.helper cache` the passwords will not be saved to a file, only stored in memory. See: https://git-scm.com/docs/git-credential-cache – S.A. Jul 20 '19 at 06:11
  • 2
    Does not work. Gives fatal: Authentication failed. Doesnt even ask for password. – Philip Rego Oct 01 '19 at 18:41
  • 14
    Just as an addendum - your private ssh-key will also be stored in plaintext in a user-accessible location, so in essence the same attack surface in both cases. – Falco Jan 07 '20 at 11:48
  • how can I use this for gitlab – anil Feb 28 '20 at 07:22
  • there's no difference for gitlab configs. you can use these commands for github, gitlab, bitbucket,... – Farhad Feb 28 '20 at 16:52
  • but setting up ssh is difficult for a first timer like me – Harsha Apr 02 '20 at 19:40
  • 1
    That doesnt add the time out, see @Andreas Bigger comment below: git config --global credential.helper 'cache --timeout=3600' – run_the_race Apr 30 '20 at 13:17
  • Does not work for me.. Now I get the error: git: 'credential-cache' is not a git command. See 'git --help'. fatal: Authentication failed for [url] – letie May 01 '20 at 14:14
  • I have to store username and passwords twice, in the above named .gitconfig and in git-credentials, so someone nasty can be sure she/he HAS the right github key;) when checking both. – Timo Nov 13 '20 at 11:41
  • 1
    Unless you put a password on your private ssh key, it is also stored in plain text, no more securely than `~/.git-credentials`, by default in `~/.ssh/id_rsa`. So the advice to use an ssh key as more secure, would need to specify a password-protected private key. In which case you'd have to type that password each time, defeating the original purpose, unless you cache it with ssh-agent – Jason S Mar 19 '21 at 13:12
  • I had to use this method with the UNSECURE option on a target machine. The secure option was not working due to some limitations. Check this for reference: https://github.com/microsoft/vcpkg/discussions/21629#discussioncomment-1708515 – tarekahf Jun 13 '22 at 17:45
470

Recommended and secure method: SSH

Create an SSH GitHub key. Go to github.comSettingsSSH and GPG keysNew SSH Key. Now save your private key to your computer.

Then, if the private key is saved as id_rsa in the ~/.ssh/ directory, we add it for authentication as such:

ssh-add -K ~/.ssh/id_rsa

A more secure method: Caching

We can use git-credential-cache to cache our username and password for a time period. Simply enter the following in your CLI (terminal or command prompt):

git config --global credential.helper cache

You can also set the timeout period (in seconds) as such:

git config --global credential.helper 'cache --timeout=3600'
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
Andreas Bigger
  • 5,264
  • 1
  • 13
  • 18
  • 41
    This did not work for me, git clone still asks for the username and password – Oliver Dec 20 '18 at 05:09
  • 16
    i do not recommend storing your password like this because "git config --global -l" would reveal your password on the console – CCC Dec 26 '18 at 08:02
  • 3
    This is not working for me. It is strange that it should work for anyone, since in gitconfig's specification there is no room for "password" – Hamish Todd Nov 28 '19 at 18:12
  • 1
    .gitconfig is the different file: .git-credentials located in your home folder contains URL to repo with your username and password in URL, just like git://username:password@server/git/repo Be careful, IT IS SAVED PLAIN TEXT PASSWORD. Use "git config --global credential.helper cache" if you cannot use ssh keys. – skabbit Apr 13 '20 at 07:11
  • When I tried to add user and password mannually the config file broke and I had to clone the repo again. Do not try this.. – letie May 01 '20 at 14:11
  • @LTV, this is a fairly well documented process. Day in and out, people update git username manually (not password please); the issue may well be on your end. –  Jul 29 '20 at 17:56
  • 1
    The ssh method is preferred, particularly if you create a pass-phrase. I find Git's instructions helpful: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh – kingaj Aug 19 '20 at 14:39
  • This answer needs a lot of elaboration on the first part "Recommended and Secure Method: SSH". A random user online needs to know the commands to execute to create an SSH key. – Shailen Oct 06 '20 at 18:13
  • 1
    Quick and insecure works, you can also change the gitconfig manually. – Timo Nov 16 '20 at 11:00
  • 6
    If you use the SSH method, you'll need to start using SSH URLs instead of git URLs - https://stackoverflow.com/questions/14762034/push-to-github-without-a-password-using-ssh-key – yndolok Feb 24 '21 at 03:32
  • 24
    "An even less secure method". Have to disagree. Does anyone here realise your passwordless private ssh key (the whole point of the question is to avoid typing your password) is stored in plain text (by default in `~/.ssh/id_rsa`, no more securely than `~/.git-credentials` ? Also the credential.helper store method does not put the password / token in .gitconfig Also due to quirks of sites like GitHub you get more fine-grained control over permissions on a Personal Access Token than an SSH public key. So for that specific case I'd say PAT with credential helper is "more secure" – Jason S Mar 19 '21 at 13:21
  • If you don't have a PIN for authenticator use `ssh-add ~/.ssh/id_rsa` instead. (Omit -K) – Halfacht May 20 '21 at 10:36
  • I faced issues in creating gpg keys, on ubuntu20.04. So I chose insecure method to save all things plaintext. – mrigendra Jul 08 '21 at 14:37
  • @CCC GitHub Personal access tokens are not revealed by `git config --global -l`. The credential cache appears to be working just fine. I set my timeout for 3 days. – Buttle Butkus Oct 31 '21 at 00:31
  • @JasonS When you generate your private ssh key, you should secure it with a passphrase. Then it is more secure than the methods that store a credential in plaintext. See: https://security.stackexchange.com/questions/183636/ssh-keygen-what-is-the-passphrase-for – krubo Feb 11 '22 at 20:57
  • 1
    @krubo The original question is how to use a Git GUI tool without entering a password for operations to the remote repository. If you secure your key with a passphrase and don't use `ssh-agent` you'll be prompted for the password each time the key is used. If you use `ssh-add` (as in this answer) which adds the key to `ssh-agent` it will ask for the key password (if any), so not exactly passwordless. My previous comment was merely to point out that passwordless ssh private key is also free text on disk, so no more secure than `~/.git-credentials` – Jason S Feb 13 '22 at 01:29
  • Note (also to myself in the future): `9 h` are `32400 s`. It might make sense to want to enter credentials once per working day. – sb813322 Dec 29 '22 at 10:22
181

Turn on the credential helper so that Git will save your password in memory for some time:

In Terminal, enter the following:

# Set Git to use the credential memory cache
git config --global credential.helper cache

By default, Git will cache your password for 15 minutes.

To change the default password cache timeout, enter the following:

# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'

From GitHub Help.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
simhumileco
  • 31,877
  • 16
  • 137
  • 115
  • 8
    you're the only one who suggested the global version which is IMPORTANT, cause it got ruined for me every time I re-cloned the repo – xeruf Jan 24 '18 at 21:56
  • 6
    How to set the timeout to infinity? I never want to enter my password again. – Avamander Apr 04 '18 at 19:33
  • 9
    @Avamander just replace the `cache` part with `store`. So, the full command will be: `git config --global credential.helper store`. Note that this will store Your password in a open-text file (without any encryption, so to say). – Aleksandar Apr 20 '18 at 06:40
  • 3
    @Casper That doesn't work with more than one account, the password isn't fetched from the store based on the e-mail like it should, instead the first one in the list is taken. – Avamander Apr 21 '18 at 09:53
  • 2
    @Avamander hm.. is that supposed to be like that or it might be a bug? What is the maximum value for the `--timeout` parameter? – Aleksandar Apr 21 '18 at 12:50
  • 2
    If you do this approach on Windows you will need to install the latest windows credential manager https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases/latest or else you will get fatal HttpRequestExceptions – David May 30 '19 at 15:31
  • After doing that, when I use git, I get the message "git: 'credential-cache' is not a git command. See 'git --help'." – John Deighan Sep 17 '19 at 02:51
  • @user1738579 Do you use GIT on Windows? Maybe this will help you: https://stackoverflow.com/questions/11693074/git-credential-cache-is-not-a-git-command – simhumileco Sep 17 '19 at 11:12
  • 1
    Works for me thanks! – Yogesh Kumar Oct 13 '21 at 06:49
  • 1
    Of interest: [commit `f13c3f28` from git 2.39 (Q4 2022)](https://github.com/git/git/commit/f13c3f28e7e8959fa23958323458b7e4437f2dda). – VonC Nov 24 '22 at 20:18
  • 1
    Note (also to myself in the future): `9 h` are `32400 s`. It might make sense to want to enter credentials once per working day. – sb813322 Dec 29 '22 at 10:22
  • Can we change the cache timeout to infinity and beyond? – alper May 06 '23 at 06:37
  • 1
    @alper Technically, you can set the cache timeout to a very large value, which would effectively make it infinite for practical purposes. It is also important to remember that any reboot will of course clear the cache. However, it's not recommended to set the cache timeout to an extremely large or infinite value, as this could potentially compromise the security of your Git repository. – simhumileco May 08 '23 at 09:01
115

You can edit the ~/.gitconfig file to store your credentials:

nano ~/.gitconfig

Which should already have

[user]
        email = your@email.com
        user = gitUSER

You should add the following at the bottom of this file.

[credential]
        helper = store

The reason I recommend this option is because it is global and if at any point you need to remove the option you know where to go and change it.

Only use this option in you personal computer.

Then when you pull | clone| enter you Git password, in general, the password will be saved in ~/.git-credentials in the format

https://gituser:gitpassword@domain.xxx

Where DOMAIN.XXX could be github.com, bitbucket.org, or others

See the documentation.

Restart your terminal.

k_o_
  • 5,143
  • 1
  • 34
  • 43
T04435
  • 12,507
  • 5
  • 54
  • 54
103

After going over dozens of Stack Overflow posts, blogs, etc., I tried out every method, and this is what I came up with. It covers everything.

The vanilla DevOps Git credentials & private packages cheat sheet

These are all the ways and tools by which you can securely authenticate Git to clone a repository without an interactive password prompt.

  • SSH public keys
    • SSH_ASKPASS
  • API access tokens
    • GIT_ASKPASS
    • .gitconfig insteadOf
    • .gitconfig [credential]
    • .git-credentials
    • .netrc
  • Private packages (for free)
  • Node.js / npm package.json
  • Python / pip / eggs requirements.txt
  • Ruby gems Gemfile
  • Go go.mod

The Silver Bullet

Want Just Works™? This is the magic silver bullet.

Get your access token (see the section in the cheat sheet if you need the GitHub or Gitea instructions for that) and set it in an environment variable (both for local development and deployment):

MY_GIT_TOKEN=xxxxxxxxxxxxxxxx

For GitHub, copy and run these lines verbatim:

git config --global url."https://api:$MY_GIT_TOKEN@github.com/".insteadOf "https://github.com/"
git config --global url."https://ssh:$MY_GIT_TOKEN@github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://git:$MY_GIT_TOKEN@github.com/".insteadOf "git@github.com:"

Congratulations. Now any automated tool cloning Git repositories won't be obstructed by a password prompt, whether using HTTPS or either style of an SSH URL.

Not using GitHub?

For other platforms (Gitea, GitHub, and Bitbucket), just change the URL. Don't change the usernames (although arbitrary, they're needed for distinct configuration entries).

Compatibility

This works locally in macOS, Linux, Windows (in Bash), Docker, CircleCI, Heroku, Akkeris, etc.

More information

See the ".gitconfig insteadOf" section of the cheat sheet.

Security

See the "Security" section of the cheat sheet.

coolaj86
  • 74,004
  • 20
  • 105
  • 125
  • 9
    What I was after was `git config --global credential."https://somegithost.com".username MyUserName`, which is _in_ your cheatsheet, but not anywhere else in this answer thread. That particular solution doesn't answer the OP's question, but it answered mine, so thanks! – TheDudeAbides Feb 14 '20 at 04:14
  • 3
    Finally: documentation on non-interactive global usage of an API access token for pipelines without Jenkins credentials helpers or Vault. – Matthew Schuchard Dec 10 '20 at 16:12
  • 1
    Not only does this not work, but now I can't commit to Git at all :-( – robcarver Sep 20 '21 at 08:49
  • @robcarver It works. However, you may not have a correct access token, or may have used the wrong kind of quote or shell (if you're on Windows, for example). You can edit ~/.gitconfig or .git/config and remove the configuration. – coolaj86 Sep 20 '21 at 09:43
  • @coolaj86 I managed to reverse it by editing gitconfig, but I can assure you it doesn't work. I'm on linux so not a shell issue and I definitely have the correct access token. – robcarver Sep 22 '21 at 08:47
  • What if I have some git remotes on github and others on my own gitlab server? How can I configure git to use the access token only for github and not for all oter git repositories? – Max N Jan 01 '22 at 23:46
  • 1
    @MaxN It's the same. You just have one set of config options per service - so rather than only 3 for github, you'd also have 3 for gitea and 3 for gitlab, and 3 for bitbucket, etc. – coolaj86 Jan 02 '22 at 04:10
  • 1
    OMG, it just works! I've been chasing this issue for 6 hours and then I see this post... In my case I'm configuring an automated installation of Python libraries directly from GitHub in an AWS Lambda Docker image. -- Thanks @coolaj86, you're a life saver. – Marin Jan 25 '22 at 01:38
  • Isn't when I enter `MY_GIT_TOKEN=xxxxxxxxxxxxxxxx` writing the access token in plain text to the `.bash_history` file? Or did I get something wrong? – sb813322 Dec 29 '22 at 10:36
  • @sb813322 enter spaces before the command and most shells will know to not save that in the history. However, on a local computer it won't matter because all desktop OSes turn on at-rest encryption by default, which is doubly enforced by the software installed by your company's IT subcontractor - that annoying "jamf" stuff. A lot of the old rules about security from the 90s - back when raptors roamed the Unix system control rooms have been superseded by / interrelated into modern hardware and software - plus it's all in the cloud anyway, you can't really secure anything yourself these days. – coolaj86 Dec 29 '22 at 14:38
  • 1
    This (like many other answers) is a hack to 'get around' git security, storing the API key as clear text. Better to 'work with' the credential helper. – Dominic Cerisano Apr 10 '23 at 18:21
  • 1
    @DominicCerisano False! This is not a hack to 'get around' git security. You're basing assumptions on old security models that don't exist on modern computers or modern cloud environments. Yes, if you have a vualt, use it. However, there are many different models as referenced in the linked article and they apply in different scenarios. This is perfectly valid for a wide range of uses cases, especially those mentioned, and caveats are mentioned in the article. – coolaj86 Apr 11 '23 at 05:04
  • @coolaj86 Wrong, and your assumptions are _ageist_. Git has a modern security model that works perfectly with modern devices and services. The git credential helper is for avoiding hacky old solutions such as storing tokens as clear text. Also I don't know what a _vualt_ (sic) is, probably something wrong there as well. – Dominic Cerisano Apr 26 '23 at 15:57
  • Followed these instructions verbatim, and got `The requested URL returned error: 403`. I'm guessing these instructions might be a little out of date? – szeitlin Aug 28 '23 at 23:08
  • @szeitlin I don't think anything about git auth has changed. 403 is forbidden, not 401 unauthorized, so it may be that the token is valid, but doesn't have access to the repo. Depending on what service you're using it's possible that additional account or token config is necessary. – coolaj86 Aug 30 '23 at 00:37
  • @coolaj86 pretty sure the token had access to the repo, so it's more likely that it's no longer valid. – szeitlin Aug 30 '23 at 16:40
85

I think it's safer to cache credentials, instead of storing it forever:

git config --global credential.helper 'cache --timeout=10800'

Now you can enter your username and password (git pull or ...), and keep using Git for the next three hours.

It is nice and safe.

The unit for timeout is seconds (three hours in this example).

Saadat
  • 163
  • 4
  • 15
Amin Shojaei
  • 5,451
  • 2
  • 38
  • 46
67

For global settings, open the terminal (from anywhere), run the following:

  git config --global user.name "your username"
  git config --global user.password "your password"

By that, any local Git repository that you have on your machine will use that information.

You can individually configure for each repository by doing:

  • open the terminal at the repository folder.

  • run the following:

      git config user.name "your username"
      git config user.password "your password"
    

It affects only that folder (because your configuration is local).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tuananhcwrs
  • 971
  • 7
  • 5
  • 17
    Isn't it dangerous having such credentials in a simple config file viewable by anyone? – bool3max May 05 '19 at 15:28
  • 2
    your question should be for another topic. Here we discus about how to config name and password for git global and locally. – Tuananhcwrs May 06 '19 at 07:30
  • 26
    I'd just like to add that asking about possible security issues of an answer has a place here as it directly influences its quality and potentially thousands of users implementing it. – Michael Kargl May 11 '19 at 16:51
  • 3
    doesn't work for me , added ```--local``` tag but again nothing happens – PayamB. Dec 04 '19 at 11:58
  • I think @bool3max question is a fair one. No-one really answered though. `git config --global` is still only accessible to the user, at `~/.gitconfig`, so in that sense it is probably no worse than a private ssh key (with no password protection) in your home directory, or things like `~/.aws/config` for aws cli. If you used `--system` for git config it would be available to all users on your computer, so better not do that, and no need to, although it would still be limited to the other users on your computer. – Jason S Mar 18 '21 at 00:21
64

Just put your credentials in the URL like this:

https://Username`**:**`Password`**@**`github.com/myRepoDir/myRepo.git`

You may store it like this:

git remote add myrepo https://Userna...

...example to use it:

git push myrepo master`

Now that is to List the URL aliases:

git remote -v

...and that the command to delete one of them:

git remote rm myrepo
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nadu
  • 2,401
  • 1
  • 25
  • 30
  • 9
    You can also leave your password out of the URL so Git will ask for your password, but not your username. – kangaroo Jul 19 '18 at 00:02
  • 1
    It's much easy and secure to use SSH instead of HTTP. So, you could keep your Git password secret and only use your SSH-Key. Information about SSH on Git: https://help.github.com/en/enterprise/2.16/user/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent `git@github.com:Username/myRepo.git` – Loich Jan 06 '20 at 14:32
  • 2
    Having your password in the url will save it to your terminal's history so this way isn't very secure. – Josh Correia Feb 19 '20 at 22:03
  • 1
    Note that a Wiki can currently only be cloned through `https`, not `ssh`, so a solution like this can be useful there. Note also that you can use an oauth-token, which is marginally more secure that your GitHub password. – AstroFloyd May 20 '20 at 15:22
  • Worked with windows credential manager, was prompted by windows for the password! – JGlass Feb 07 '22 at 14:47
62

You can use git-credential-store to store your passwords unencrypted on the disk, protected only by the permissions of the file system.

Example

git config credential.helper store
git push http://example.com/repo.git

Username: <type your username>
Password: <type your password>

[Several days later]

git push http://example.com/repo.git

[Your credentials are used automatically]

You can check the credentials stored in the file ~/.git-credentials.

For more information, visit git-credential-store - Helper to store credentials on disk.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
46

Store username and password in .git-credentials

.git-credentials is where your username and password (access token) is stored when you run git config --global credential.helper store, which is what other answers suggest, and then type in your username and password or access token:

https://${username}:${password_or_access_token}@github.com

So, in order to save the username and password (access token):

git config --global credential.helper store
echo "https://${username}:${password_or_access_token}@github.com" > ~/.git-credentials

Replace ${username} with your username, ${password_or_access_token} with your password (not recommended) or your access token.

NOTE that you must provide access token if you enabled 2FA on GitHub.

Using access token is recommended.

This is very useful for a GitHub robot, e.g. to solve Chain automated builds in the same Docker Hub repository by having rules for different branch and then trigger it by pushing to it in the post_push hook in Docker Hub.

An example of this can be seen here on Stack Overflow.

JiaHao Xu
  • 2,452
  • 16
  • 31
  • 2
    Thanks, you're a life savior! We can also set https://${access_token}:${access_token}@github.com – Lucas Mendes Mota Da Fonseca Nov 14 '19 at 15:09
  • 2
    @LucasMendesMotaDaFonseca access token can be used as username??? – JiaHao Xu Nov 24 '19 at 03:48
  • @PeterMortensen It's definitely not and now it is replaced with 'hook'. – JiaHao Xu Sep 14 '21 at 03:34
  • is working also with bitBucket? – SL5net Sep 17 '21 at 14:33
  • @SL5net I think this should work with any sites. However, bitbucket requires users with 2FA (which I enabled) to clone with ssh key, so I can’t test it. – JiaHao Xu Sep 18 '21 at 06:34
  • 1
    From all the different solutions, this is the one that worked for me. thank you! – Valera Feb 22 '23 at 22:00
  • 1
    @MichaelN Hmmm so it doesn't work with `https://` prefix on your system? Which `git` and os are you using? – JiaHao Xu Apr 11 '23 at 04:04
  • @JiaHaoXu On macOS… echo “https://username:password@github.com“ > ~/.git-credentials worked for me, where you replace username with your username and password with your password or access token. The $ syntax doesn’t work in Unix. Add https:// Stack is removing it. – Michael N Apr 12 '23 at 05:05
  • Thanks, I didn't know that it doesn't need `https://` prefix, the `${username}` in my answer means that you should replace that with your username, which is taken from bash variable expansion. – JiaHao Xu Apr 17 '23 at 10:46
  • 1
    @MichaelN I've clarified the instruction and now it should be clear on how to save the password and username. – JiaHao Xu Apr 17 '23 at 10:48
  • Be sure to remove the `"` in the `.git-credentials` file in case your command saves them inside – Simon Apr 26 '23 at 08:08
  • @Simon Thanks for pointing it out, I just realize that the character I typed in is not the `"` but rather another character similar to it, I've updated my answer and fixed it. – JiaHao Xu Apr 26 '23 at 12:39
38

Apart from editing the ~/.gitconfig file, that you can do if you call from the command line:

git config --local --edit

or

git config --global --edit

enter image description here Editing git config file in default text editor

You can also use the command line to edit the git config file directly (without the editor)

git config --local user.name 'your username'
git config --local user.password 'your password'

or

git config --global user.name 'your username'
git config --global user.password 'your password'

Note to always use single quotes. Your username and password may use some characters that would break your password if you use double quotes.

--local or --global means configuration parameters are saved for the project or for the OS user.

prosti
  • 42,291
  • 14
  • 186
  • 151
  • Check also this [one](https://stackoverflow.com/a/56506187/5884955) that explains even more. – prosti Jul 05 '19 at 08:14
  • Are you sure single quotes will work on Windows, other than inside WSL? – Yitz Aug 02 '20 at 11:44
  • I usually do things from Windows PowerShell and this single quote worked on Windows (no WSL). – prosti Aug 02 '20 at 12:39
  • What is *"the os user"*? Do you mean by *"the OS user"*? (OS = operating system). If so, what does that mean? Or something else? Can you rephrase? – Peter Mortensen Sep 08 '21 at 15:56
  • The first sentence is close to incomprehensible. Can you [rephrase](https://stackoverflow.com/posts/55717179/edit), please? (But ***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today.) – Peter Mortensen Sep 08 '21 at 15:57
  • Thanks, @PeterMortensen, I improved and let me know if this is OK now. – prosti Sep 27 '21 at 12:24
27

You will be more secure if you use SSH authentication than username/password authentication.

If you are using a Mac, SSH client authentication is integrated into the macOS keychain. Once you have created an SSH key, type into your terminal:

ssh-add -K ~/.ssh/id_rsa

This will add the SSH private key to the macOS keychain. The Git client will use SSH when it connects to the remote server. As long as you have registered your ssh public key with the server, you will be fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Birol Efe
  • 1,605
  • 16
  • 14
  • 1
    should be k not K? – dez93_2000 Apr 28 '18 at 15:23
  • 1
    FYI: I am working on a Mac. Having said that, from the "man" info: "-k" When loading keys into or deleting keys from the agent, process plain private keys only and skip certificates. "-K" When adding identities, each passphrase will also be stored in the user's keychain. When removing identities with -d, each passphrase will be removed from it. – Birol Efe Apr 30 '18 at 11:35
  • 3
    I don't think this work for https-based repositories. – zakmck May 19 '18 at 13:49
  • 6
    This answer seems to confuse passwords (HTTPS repos) with SSH private keys. – Steve Bennett May 23 '18 at 04:51
  • 2
    Yes, my recommended solution is for SSH, not HTTPS. Hence, the command "ssh-add". For HTTPS it would be the solution mentioned above "git credential-osxkeychain" (on Mac). – Birol Efe Jul 20 '18 at 10:25
  • 2
    I disagree. You can't be more secure by giving access to the host an `SSH` access. Using HTTP authentication, someone who steal the credentials would only have access to `GitHub/GitLab`. Also token are designed to have a limited life. – Dimitri Kopriwa Oct 01 '18 at 20:50
25

As of 2021, there is a secure user-friendly cross-platform solution for HTTPS remotes. No more typing passwords! No more SSH keys! No more personal access tokens!

Install Git Credential Manager developed by GitHub (downloads). It supports passwordless in-browser OAuth authentication to GitHub, BitBucket, Azure and GitLab. This means you can enable two-factor authentication on GitHub and the other platforms, greatly improving the security of your accounts.

When you push, you are offered a choice of authentication methods:

> git push
Select an authentication method for 'https://github.com/':
  1. Web browser (default)
  2. Device code
  3. Personal access token
option (enter for default): 1
info: please complete authentication in your browser...

On Linux, a tiny bit of setup is required. The following caches credentials in memory for 20 hours, so you have to authenticate at most once per day.

git-credential-manager-core configure
git config --global credential.credentialStore cache
git config --global credential.cacheoptions "--timeout 72000"

Power users familiar with gnome-keyring or KWallet may prefer to change the credential store to libsecret.

Cosmetic configuration (docs):

  1. Prefer choosing authentication method at terminal rather than in GUI (fewer clicks)
  2. Always use browser method rather than be asked every time (even fewer keypresses)
git config --global credential.guiPrompt false
git config --global credential.gitHubAuthModes browser
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
  • I remain a huge fan of GCM but if you find it difficult to install on Linux, you can use git-credential-oauth https://stackoverflow.com/a/74415927/284795 – Colonel Panic Nov 12 '22 at 20:00
23

Just use

git config --global credential.helper store

And do the git pull. It will ask for a username and password. From now on it will not provide any prompt for username and password. It will store the details.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Srikanth Josyula
  • 790
  • 7
  • 15
  • 13
    You've just basically repeated the [accepted answer](https://stackoverflow.com/a/35942890/11342519). – jsamol Sep 07 '19 at 12:43
20

To save your user name and user password into github account just run these command in sequence.

git config --global user.name "userName"
git config --global user.email "usernam@gmail.com"
git config --global user.password "userPassword"
git config --global credential.helper store
git config --list --show-origin

Then generate a key using below command:

ssh-keygen -t rsa -C "useremail@gmail.com"

Note: Copy the file location where id_rsa file gets created Then go to that file location -->open gitbash or command prompt --> Run a command - cat id_rsa.pub

SSH key will be dispayed, copy this SSH key and paste it in your gihub/gitlab account

Sudheer Singh
  • 555
  • 5
  • 10
15

In that case, you need git credential helper to tell Git to remember your GitHub password and username by using following command line:

git config --global credential.helper wincred

And if you are using a repository using an SSH key then you need the SSH key to authenticate.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
shaw
  • 151
  • 1
  • 2
  • 3
    `wincred` is obsoleted, see https://stackoverflow.com/a/53184233/5281824 – weaming Jul 15 '20 at 07:46
  • To add to what @weaming said, on Windows, manager-core is now bundled with the Git installer for Windows https://github.com/microsoft/Git-Credential-Manager-Core – Jason S Mar 19 '21 at 13:35
15

None of the previous answers worked for me. I kept getting the following every time I wanted to fetch or pull:

Enter passphrase for key '/Users/myusername/.ssh/id_rsa':


For Macs

I was able to stop it from asking my passphrase by:

  1. Open config by running: vi ~/.ssh/config
  2. Added the following: UseKeychain yes
  3. Saved and quit: Press Esc, and then enter :wq!

For Windows

I was able to get it to work using the information in this Stack Exchange post: How to avoid being asked passphrase each time I push to Bitbucket

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gene Parcellano
  • 5,799
  • 5
  • 36
  • 43
14

Check official Git documentation:

If you use the SSH transport for connecting to remotes, it’s possible for you to have a key without a passphrase, which allows you to securely transfer data without typing in your username and password. However, this isn’t possible with the HTTP protocols – every connection needs a username and password. This gets even harder for systems with two-factor authentication, where the token you use for a password is randomly generated and unpronounceable.

Fortunately, Git has a credentials system that can help with this. Git has a few options provided in the box:

  • The default is not to cache at all. Every connection will prompt you for your username and password.

  • The “cache” mode keeps credentials in memory for a certain period of time. None of the passwords are ever stored on disk, and they are purged from the cache after 15 minutes.

  • The “store” mode saves the credentials to a plain-text file on disk, and they never expire. This means that until you change your password for the Git host, you won’t ever have to type in your credentials again. The downside of this approach is that your passwords are stored in cleartext in a plain file in your home directory.

  • If you’re using a Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account. This method stores the credentials on disk, and they never expire, but they’re encrypted with the same system that stores HTTPS certificates and Safari auto-fills.

  • If you’re using Windows, you can install a helper called “Git Credential Manager for Windows.” This is similar to the “osxkeychain” helper described above, but uses the Windows Credential Store to control sensitive information. It can be found at https://github.com/Microsoft/Git-Credential-Manager-for-Windows.

You can choose one of these methods by setting a Git configuration value:

git config --global credential.helper cache

git config --global credential.helper store

From 7.14 Git Tools - Credential Storage

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sma Ma
  • 3,343
  • 2
  • 31
  • 39
12

Save the username and password globally:

git config --global user.name "fname lname"
git config --global user.email "example@gmail.com"
git config --global user.password "secret"

Get a specific setting,

git config --global --get user.name
git config --global --get user.email
git config --global --get user.password

Getting all Git settings:

git config --list --show-origin
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mrigendra
  • 1,472
  • 3
  • 19
  • 33
  • 3
    I have done all the settings globally, username, email, and password, still when I push the code on GitHub, It asks for the username and password every time – Jwala Kumar Sep 25 '21 at 10:59
  • Yes, there are multiple places git settings are saved. Maybe in project .git folder some project settings are defaulted and take precedence. – mrigendra Oct 09 '21 at 11:25
11

If security is not a concern for the git client, edit the url this way:

git remote set-url origin https://${access_token}@github.com/${someone}/${somerepo}.git

Same in the git clone case:

git clone https://${access_token}@github.com/${someone}/${somerepo}.git

I personally do not favor git config with global domain, since that would be a mess in a multiple-accounts case.

access_token is what you could generate in Settings / Developer settings / Personal access tokens. Remember to grant it with repo scope.

aGuegu
  • 1,813
  • 1
  • 21
  • 22
9

From the comment by rofrol, on Linux Ubuntu, from this answer, here's how to do it on Ubuntu:

sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

Some other distributions provide the binary, so you don't have to build it.

In OS X, it typically comes "built" with a default module added of "osxkeychain", so you get it for free. Both the OS X built-in one and the homebrew variety have it present by default.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
8

After reading the answers in full and experimenting with most of the answers to this question, I eventually found the procedure that works for me. I want to share it in case someone has to deal with a complex use case, but still do not want to go through all the answers and the gitcredentials, gitcredentials-store etc. man pages, as I did.

Find below the procedure I suggest IF you (like me) have to deal with several repositories from several providers (GitLab, GitHub, Bitbucket, etc.) using several different username / password combinations. If you instead have only a single account to work with, then you might be better off employing the git config --global credential.helper store or git config --global user.name "your username" etc. solutions that have been very well explained in previous answers.

My solution:

  1. Unset global credentials helper, in case some former experimentation gets in the way :)

    git config --global --unset credentials.helper
    
  2. Move to the root directory of your repo and disable the local credential helper (if needed)

    cd /path/to/my/repo
    git config --unset credential.helper`
    
  3. Create a file to store your repo's credentials into

    git config credential.helper 'store --file ~/.git_repo_credentials'
    

    Note: this command creates a new file named ".git_repo_credentials" into your home directory, to which Git stores your credentials. If you do not specify a file name, Git uses the default ".git_credentials". In this case simply issuing the following command will do:

    git config credential.helper store
    
  4. set your username

    git config credential.*.username my_user_name
    

    Note: using "*" is usually ok if your repositories are from the same provider (e.g. GitLab). If instead your repositories are hosted by different providers then I suggest to explicitly set the link to the provider for every repository, like in the following example (for GitLab):

    git config credential.https://gitlab.com.username my_user_name
    

At this point, if you issue a command requiring your credentials (e.g. git pull), you will be asked for the password corresponding to "my_user_name". This is only required once because git stores the credentials to ".git_repo_credentials" and automatically uses the same data at subsequent accesses.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sal Borrelli
  • 2,201
  • 19
  • 19
  • just to note, here when using * I got: "warning: url has no scheme: * fatal: credential url cannot be parsed: *" . So I had to specify "credential.https://github.com.username". – Tonsic Nov 21 '21 at 18:37
  • (stackoverflow comment replaced the `https://github...` with `github...` in my last comment) – Tonsic Nov 21 '21 at 18:49
  • The best flexible option to work with several git providers from a single computer.Thanks. If anyone is looking for this behaviour using ssh keys, check your ~/.ssh/config file and add custom ssh key to be used each git server provider – danipenaperez Aug 11 '23 at 09:04
8

For Windows users, look at the .gitconfig file and check what has been configured for the credential helper. If you have the following...

[credential "helperselector"] selected = wincred

you'll find the credentials in the Windows Credential Manager.

Enter image description here

There you can edit the credential.

Note: Wincred has been deprecated, see...

https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-this-project-is-no-longer-being-maintained-warning

So alternatively you may want to reconfigure Git to use the built-in Git credential manager...

git config --global credential.helper manager
Mick
  • 6,527
  • 4
  • 52
  • 67
  • I am having an issue with the manager-core helper, where my credentials disappear every day - Any clue on how to solve this? – Jonathan Dec 22 '20 at 17:26
  • The edit was the answer I was looking for, THANKS! – generic-user Jan 19 '21 at 12:48
  • @Jonathan The Credential manager bundled with Git for Windows changed a few times recently so the easiest option is to just download the newest Git for Windows and install over the top and select the credential manager in the installer. The credential manager is a separate utility, which you can see it on GitHub at https://github.com/microsoft/Git-Credential-Manager-Core, but better to just let the Git for Windows installer, install it, so you know you have version compatibility – Jason S Mar 19 '21 at 13:46
  • The link is broken (404). – Peter Mortensen Sep 08 '21 at 16:59
  • This was the only command that worked for me in Windows, however after running it I had to do a 'git fetch' and 'git pull origin main' to get the Windows creds window to pop up. Seems to be cached since – heyjon Aug 26 '22 at 22:52
7

If you are using the Git Credential Manager on Windows...

git config -l should show:

credential.helper=manager

However, if you are not getting prompted for a credential then follow these steps:

  1. Open Control Panel from the Start menu
  2. Select User Accounts
  3. Select Manage your credentials in the left hand menu
  4. Delete any credentials related to Git or GitHub

Also ensure you have not set HTTP_PROXY, HTTPS_PROXY, NO_PROXY environmental variables if you have proxy and your Git server is on the internal network.

You can also test Git fetch/push/pull using git-gui which links to credential manager binaries in C:\Users\<username>\AppData\Local\Programs\Git\mingw64\libexec\git-core

Armfoot
  • 4,663
  • 5
  • 45
  • 60
5

The GitHub recommendations have now changed, and the best method is also the simplest. Details here

  1. Install Github official cli. E.g. for mac: brew install gh.
  2. type gh auth login in your terminal, then follow the prompts.
Yann Dubois
  • 1,195
  • 15
  • 16
2
git config --global user.name "your username"
git config --global user.password "your password"

Check

git config --list
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Keshav Gera
  • 10,807
  • 1
  • 75
  • 53
2

For Windows users, this way will work:

Note: If you have enabled two-factor authentication for GitHub, disable it for a while

  • Step 1

    Go to Control PanelUser AccountsCredential ManagerWindows Credentials

  • Step 2

    Go to the Generic Credentials section → Add a generic credential

    Enter image description here

  • Step 3 - Fill in the fields

    Internet or network address: git.https://github.com

    User name: your GitHub username

    Password: your GitHub username

    Enter image description here

    And now click on OK. This will save the password and the username of your GitHub account to your local machine

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Niroshan Ratnayake
  • 3,433
  • 3
  • 20
  • 18
2

Two-factor authentication has changed how users authenticate to websites, but Git still assumes users can type a password from memory.

Introducing git-credential-oauth: a Git credential helper that securely authenticates to GitHub, GitLab, BitBucket and other forges using OAuth.

No more passwords! No more personal access tokens! No more SSH keys!

The first time you push, the helper will open a browser window to authenticate. Subsequent pushes within the cache timeout require no interaction.

Install from https://github.com/hickford/git-credential-oauth/releases/

Configure with:

git config --global --unset-all credential.helper
git config --global --add credential.helper "cache --timeout 7200" # two hours
git config --global --add credential.helper oauth
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
1

Your question:

I want to use a push and pull automatically in Git Extensions, Sourcetree or any other Git GUI without entering my username and password in a prompt, every time.
So how can I save my credentials in Git?

If you are in github or other providers I would recommend not to save them in the Git such as ~/.git-credentials but treat them as Encrypted secrets as they should.

Put the credential to the following format:

https://your_user_name:your_token@github.com/your_user_name/your_repo_name.git

Put it as encrypted secrets like secrets.REPOSITORY:

Actionsecrets

Then you can use it to clone either public of private repos along with its submodules as well as to do a push and pull automatically

# put the credentials in a variable
export REPOSITORY=${{ secrets.REPOSITORY }}

# git clone public or private repos
git clone --recurse-submodules -j8 ${REPOSITORY}

# git pull will do automatic
cd /path/to/the/repo
git pull

# git push to a branch in the repo
git add . && \
  git commit -m "Action from ${GITHUB_SHA}" && \
  git push --force $REPOSITORY master:$BRANCH
eQ19
  • 9,880
  • 3
  • 65
  • 77
1

On macOS, you can use the system keychain for security. I believe this is the most secure method for websites like Overleaf, which only offers https access (unless you link a github repository of yours).

The following git command activates this functionality.

$ git config --global credential.helper osxkeychain

(Additionally, as I write in the Edit below, make sure you disable other credential helpers so that git won't save your password, e.g., in plain text.) Then, you clone the git repository:

$ git clone https://git.overleaf.com/blahblah

This asks the password. Enter it, and you can see it in macOS' built-in KeyChain Access app.

In this case, you can find the entry for the URL with the name git.overleaf.com, which matches the git URL.

For better security, you can require all apps to ask for your permission. You can remove git from the "Always allow access by these applications" so that even git will not be able to get the password without your permission.

Keychain Access config

Note:
However, I noticed that some apps can still somehow git pull without my permission. This is weird because, in this case, Overleaf's git repository only offers https access. (I.e. there's no loophole through SSH.) If I change my password, I can temporarily block these apps from doing pull, but after I re-register my new password, these apps can do the pull again... Even if I check "Ask for Keychain password". Might be a misconfiguration or even a bug in macOS (Ventura).

I've opened a Q&A on this in AskDifferent: https://apple.stackexchange.com/questions/459108/keychain-access-loophole-for-git-https

Edit:
I found the problem. Git still had the configuration to store the credential written down in the global settings (~/.git-config). So, you need to make sure you have the settings correct for different resolutions. This includes per-project, global (git config edit --system) and system (git config edit --system) should have the [credential] set to helper = osxkeychain only.

After you edit the settings, check ~/.git-credentials and see there's no password stored unintentionally (in plain text).

Dean
  • 537
  • 4
  • 8
0

For gitlab users having the same issue-

you can setup a deploy token to clone or pull from your repository (you can not push code to the repo with a deploy token).

Here you can know more about gitlab deploy tokens: https://docs.gitlab.com/ee/user/project/deploy_tokens/index.html

Once you create the deploy token , use the following to clone a repo :

git clone https://${username}:${deploy_token}@gitlab.com/yourusername/yourreponame.git

I think this approach is better than saving git username and git password globally ( for instance it can be unsafe in a remote shared machine)

  • 1
    Note that if your Git is set with [`git config --system transfer.credentialsInUrl die`](https://stackoverflow.com/a/72649714/6309), such a URL would not work. – VonC Aug 09 '22 at 06:46
  • Thanks for pointing that out. And I understand it is a security loophole – Tamjid Rayhan Aug 09 '22 at 11:27
  • Yes, depending on the context, those URLs can be banned. – VonC Aug 09 '22 at 11:57
-1

You can just simply modify ~/.git-credentials

then add the following line:

git:https://<user>:<token/password>@gitlab.com

that's it

TarangP
  • 2,711
  • 5
  • 20
  • 41
  • It seems both username and password need to be urlencoded--e.g., if your username is an email, replace @ with %40 , etc. – tsbertalan Feb 21 '23 at 00:20