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
When you use https for Git pull & push, just configure remote.origin.url
for your project, to avoid input username (or/and password) every time you push.
How to configure remote.origin.url
:
URL format: https://{username:password@}github.com/{owner}/{repo} Parameters in URL: * username
Optional, the username to use when needed.
authentication, if specified, no need to enter username again when need authentication. Don't use email; use your username that has no "@", otherwise the URL can't be parsed correctly, * password optional, the password to use when need authentication. If specified, there isn't any need to enter the password again when needing authentication. Tip: this value is stored as plain text, so for security concerns, don't specify this parameter, * e.g git config remote.origin.url https://eric@github.com/eric/myproject
ssh
I think using ssh
protocol is a better solution than https
, even though the setup step is a little more complex.
Rough steps:
ssh-keygen
on Linux, on windows msysgit
provide similar commands.~/.ssh
. And add it to the ssh agent via ssh-add
command.remote.origin.url
of the Git repository to ssh
style, e.g., git@gitlab.com:myaccount/myrepo.git
Tips:
https
and ssh
protocol.Simply changing remote.origin.url
will be enough, or you can edit repo_home/.git/config
directly to change the value (e.g using vi
on Linux).
Usually I add a line for each protocol, and comment out one of them using #
.
E.g.
[remote "origin"] url = git@gitlab.com:myaccount/myrepo.git # url = https://myaccount@gitlab.com/myaccount/myrepo.git fetch = +refs/heads/*:refs/remotes/origin/*