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 pull from Github using my PC, it requires username and password, but not when using the laptop!
I don't want to type my username and password every time I interact with origin. What I am missing here?
A common mistake 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:
This is documented at GitHub: Switching remote URLs from HTTPS to SSH.
When you use https for git pull & push, just config
remote.origin.url
for your project, to avoid input username (or/and password) everytime you push.How to config
remote.origin.url
:@Update - using
ssh
I think using
ssh
protocol is a better solution thanhttps
, even though the setup step is a little more complex.Rough steps:
ssh-keygen
on linux, on windowsmsysgit
provide similar commands.~/.ssh
. And add it to ssh agent viassh-add
command.remote.origin.url
of git repository tossh
style, e.ggit@gitlab.com:myaccount/myrepo.git
Tips:
@Update - Switch between
https
andssh
protocol.Simply change
remote.origin.url
will be enough, or you can editrepo_home/.git/config
directly to change the value (e.g usingvi
on linux).Usually I add a line for each protocol, and comment out one of them using
#
.e.g