How to push different projects to repositories of different GitHub accounts?

Viewed 163

I have 2 accounts on GitHub. I want to be able to push particular projects to repositories of one account and some to another GitHub account.

How to make it happen? I am on Mac OS.

2 Answers

This article https://linuxize.com/post/how-to-configure-git-username-and-email/ helped me solve this problem. Answering to my own question after a while.

Helpful Extracts from the article:

Git allows you to set a global and per-project username and email address. You can set or change your git identity using the git config command. Changes only affect future commits. The name and email associated with the commits you made prior to the change are not affected.

Setting Global Git Username and Password. The global git username and password are associated with commits on all repositories on your system that don’t have repository-specific values. To set your global commit name and email address run the git config command with the --global option:

$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@yourdomain.com"

Setting Git Username and Password for a Single Repository. If you want to use a different username or email address for a specific repository, run the git config command without the --global option from within the repository directory. Let’s say you want to set a repository-specific username and email address for a stored in the ~/Code/myapp directory. Navigate to the folder needed.

$ cd ~/Code/myapp

Set a Git username and email address:

git config user.name "Your Name"
git config user.email "youremail@yourdomain.com"

That is it! Now if you make any commits and changes, it will be held under the specified name and email.

Related