Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write .netrc for two accounts for skipping typing password when to git push?

Tags:

git

passwords

It is simple to skip typing password when to execute git psuh command.

vim  .netrc
machine github.com
login user1
password  pass-user1

How to write .netrc for two accounts for skipping typing password when to git push?

It is no use to write the .netrc as following.

vim  .netrc
machine github.com
login user1
password  pass-user1
login user2
password  pass-user2

Edit .netrc as below according to VonC.

machine github.com login user1 password  pass-user1
machine github.com login user2 password  pass-user2 

Strange errors for git push.

git push -u origin master -f
remote: Permission to user2/test.git denied to user1.
fatal: unable to access 'https://github.com/user2/test/': The requested URL returned error: 403

git remote -v
origin  https://github.com/user2/test (fetch)
origin  https://github.com/user2/test (push)
like image 826
showkey Avatar asked Oct 19 '25 05:10

showkey


2 Answers

The correct syntax would repeat the machine.
And you can write both entries on their separate lines:

machine github.com login user1 password  pass-user1
machine github.com login user2 password  pass-user2

But then, make sure your origin remote URL specifies one of the two users:

If you already had an origin remote defined, change it with:

git remote set-url origin https://[email protected]/user2/arepo.git

But if you are using a new local repo, without any origin, add it with:

git remote add origin https://[email protected]/user2/arepo.git
like image 66
VonC Avatar answered Oct 21 '25 20:10

VonC


1.setting in .netrc for two accounts.

machine github.com login user1 password  pass-user1
machine github.com login user2 password  pass-user2

2.add origin for git push.

git remote add origin   https://[email protected]/user2/arepo.git

Not

git remote set-up origin https://[email protected]/user2/arepo.git
like image 38
showkey Avatar answered Oct 21 '25 20:10

showkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!