I cloned a Git repository from my GitHub account to my PC.
I want to work with both my PC and laptop, but with one GitHub account.
When I try to push to or p
Run the following command to enable credential caching:
$ git config credential.helper store
$ git push https://github.com/owner/repo.git
Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>
You should also specify caching expire,
git config --global credential.helper 'cache --timeout 7200'
After enabling credential caching, it will be cached for 7200 seconds (2 hour).
Source: Set Up Git
The following command will save your password in memory for some time (for Git 1.7.10 or newer).
$ git config --global credential.helper cache
# Set git to use the credential memory cache
$ git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after one hour (setting is in seconds)
A common cause is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:
git remote set-url origin git@github.com:username/repo.git
This is documented at GitHub: Switching remote URLs from HTTPS to SSH.
Updating your Git configuration file directly (if you do not want to memorize fancy commands):
Open your .git/config
file in your favorite text editor. It will be in the folder that you cloned or in the repository that you performed git init
in. Go into that repository. .git
is a hidden folder, and pressing Ctrl + H should show the hidden folder, (ls -a
in terminal).
Below is a sample of the .git/config
file. Copy and paste these lines and be sure to update those lines with your Git information.
[user]
name = Tux
email = tux@gmail.com
username = happy_feet
[remote "origin"]
url = https://github.com/happy_feet/my_code.git
fetch = +refs/heads/*:refs/remotes/origin/*
Change the URL part with the following format for SSH:
url = git@github.com:happy_feet/my_code.git
(The above formats do not change with various Git remote servers like GitHub or Bitbucket. It's the same if you are using Git for version control):
Note: The SSH way of connecting to a remote Git repository will require you to add your public SSH key to your Git remote server (like GitHub or Bitbucket. Search the settings page for SSH keys).
To know how to generate your SSH keys, refer to: Creating SSH keys
If the SSH key or .netrc
file did not work for you, then another simple, but less secure solution, that could work for you is git-credential-store - Helper to store credentials on disk:
git config --global credential.helper store
By default, credentials will be saved in file ~/.git-credentials
. It will be created and written to.
Please note using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions. If this may not be an acceptable security tradeoff.
If you are using Git (for example, Git Bash) under Windows (and if you don't want to switch from HTTPS to SSH), you could also use Git Credential Manager for Windows
This application will keep the username and password for you...