A friend and myself are sharing my computer. I\'ve made pushes to GitHub using the git bash shell on Windows 7. Now we\'re in a different project on that computer and I need
As mentioned before, you can use
git config user.name her_username
git config user.email her_email
to manually set username and email for single repo, but you have to add this command:
git commit --amend --reset-author
if you have already tried to push before the change. Otherwise the changes doesn't appear in config file.
I have been using one machine to push code to two different GitHub accounts with different username. Assuming you already set up one account and want to add a new one:
ssh-keygen -t rsa -C "myaddress@example.com"
id_rsa
. Give it a different name, e.g. id_rsa_another
Settings -> SSH and GPG keys -> New SSH key -> Give a label and paste the key -> Add SSH key
ssh-add ~/.ssh/id_rsa_another
touch ~/.ssh/config
and edit the file by providing configurations to your accounts:#first account
Host github.com-first
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#another account
Host github.com-another
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_another
Now you should be able to push from different accounts depending on what key you add to the ssh agent, i.e. to use your first account, do
ssh-add ~/.ssh/id_rsa
.
You might also want to change your user email:
git config --global user.email "myaddress@example.com"
or clean out ssh keys in case of permission error when pusing code to one of the accounts:
ssh-add -D
If you use different windows user, your SSH key and git settings will be independent.
If this is not an option for you, then your friend should add your SSH key to her Github account.
Although, previous solution will keep you pushing as yourself, but it will allow you to push into her repo. If you don't want this and work in different folder on the same pc, you can setup username and email locally inside a folder with git by removing -g
flag of the config command:
git config user.name her_username
git config user.email her_email
Alternatively, if you push over https
protocol, Github will prompt for username/password every time (unless you use a password manager).
Follow the following steps:
# you can check what's currently:
git config user.name
git config user.email
git config user.name "your_github_username"
git config user.email "your_github_email"
# Again check what's currently:
git config user.name
git config user.email
git log
# once you're confirmed that it's tagged to you, then you should move to step 3
In case, the author is wrong then you can easily undo last commit without losing changes
Also, before moving to step3, don't forget to follow step one for sanity check.!
git config --local credential.helper ""
git push
# it will ask you to enter your github_username and github_password
Go to Credential Manager Go to Windows Credentials Delete the entries under Generic Credentials Try connecting again.
You can add a new remote URL for the other username using git remote add origin-username https://username@github.expedia.biz/repository_name.git
After this, if you'll push using git push -u origin-username master
, this will prompt you for the password.