skip to Main Content

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


  1. Chosen as BEST ANSWER

    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 "[email protected]"
    

    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 "[email protected]"
    

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


  2. 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 [email protected]:<git_username>/<repo_name>.git
    

    After that when you push your code in your remote repository, your code will be pushed specific account repository.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search