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.
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.
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 configcommand. 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 configcommand with the--globaloption:
$ 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 configcommand without the--globaloption 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.
Please generate a ssh key for your mac machine following github official doc https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
Then add it in your both github accounts. Then clone your repository using ssh.
git clone git@github.com:<git_username>/<repo_name>.git
After that when you push your code in your remote repository, your code will be pushed specific account repository.