I git push
my work to a remote Git repository.
Every push
will prompt me to input username
and password
. I would
Running the below command solved the problem for me.
git config --global credential.helper wincred
Please refer the below github documentation:
https://help.github.com/articles/caching-your-github-password-in-git/
As far as I know, there are simply two safe ways: ssh or passwd encrypted using a keystore.
cat ~/.ssh/id_rsa.pub
, paste it there, name and save it (if you have no such file, generate one for yourself by ssh-keygen -t rsa
- just Enter for all prompts);git remote set-url origin git+ssh://git@github.com/username/reponame.git
- you can check it first by git remote -v
);touch t; git add t; git commit -m "test"; git push
and confirm yes to enjoy the password-free world.If you just use git config --global credential.helper store
as others mentioned, your unencrypted passwords will be just stored in a plain text under ~/.git-credentials
which is not safe as it sounds.
Try to encrypt it as
sudo apt-get install libgnome-keyring-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/gnome-keyring
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
git config --global credential.helper store
In this case, you are using
https://git@github.com/username/reponame.git
.
You can use the git-credential-store via
git config credential.helper store
which stores your password unencrypted in the file system:
Using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions. If this is not an acceptable security tradeoff, try git-credential-cache, or find a helper that integrates with secure storage provided by your operating system.
Use the git-credential-cache which by default stores the password for 15 minutes.
git config credential.helper cache
to set a different timeout, use --timeout
(here 5 minutes)
git config credential.helper 'cache --timeout=300'
- 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. Running the following on the command line will enable this feature:
git config --global credential.helper osxkeychain
. You'll need to store the credentials in the Keychain using the Keychain app as well.- 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. [emphases mine]
On Windows operating system use this instead, this works for me:
https://{Username}:{Password}@github.com/{Username}/{repo}.git
e.g.
git clone https://{Username}:{Password}@github.com/{Username}/{repo}.git
git pull https://{Username}:{Password}@github.com/{Username}/{repo}.git
git remote add origin https://{Username}:{Password}@github.com/{Username}/{repo}.git
git push origin master
If your PC is secure or you don't care about password security, this can be achieved very simply. Assuming that the remote repository is on GitHub and origin
is your local name for the remote repository, use this command
git remote set-url --push origin https://<username>:<password>@github.com/<repo>
The --push
flag ensures this changes the URL of the repository for the git push
command only. (The question asked in the original post is about git push
command only. Requiring a username+password only for push operations is the normal setup for public repositories on GitHub . Note that private repositories on GitHub would also require a username+password for pull and fetch operations, so for a private repository you would not want to use the --push flag
...)
WARNING: This is inherently unsecure because:
your ISP, or anyone logging your network accesses, can easily see the password in plain text in the URL;
anyone who gains access to your PC can view your password using git remote show origin
.
That's why using an SSH key is the accepted answer.
Even an SSH key is not totally secure. Anyone who gains access to your PC can still, for example, make pushes which wreck your repository or - worse - push commits making subtle changes to your code. (All pushed commits are obviously highly visible on GitHub. But if someone wanted to change your code surreptitiously, they could --amend
a previous commit without changing the commit message, and then force push it. That would be stealthy and quite hard to notice in practice.)
But revealing your password is worse. If an attacker gains knowledge of your username+password, they can do things like lock you out of your own account, delete your account, permanently delete the repository, etc.
Alternatively - for simplicity and security - you can supply only your username in the URL, so that you will have to type your password every time you git push
but you will not have to give your username each time. (I quite like this approach, having to type the password gives me a pause to think each time I git push
, so I cannot git push
by accident.)
git remote set-url --push origin https://<username>@github.com/<repo>
My Solution on Windows:
ssh-keygen -t rsa
(Press enter for all values)Your public key has been saved in /c/Users/<your_user_name_here>/.ssh/id_rsa.pub