Skip to content

Workflow: Using GitHub Enterprise & GitHub w different GitHub accounts in the same RStudio

Halina Do-Linh edited this page Nov 16, 2022 · 3 revisions

The Big Idea

  • You have two GitHub accounts - one associated with a work email address and one associated with a personal email address
    • 🏢 Your work email address was used to create a GitHub Enterprise account
    • 🏡 Your personal email address was used to create a GitHub account
  • You're working on your local machine in RStudio
  • And you want to choose which GitHub account to use depending on which repository you're working in
  • There are two workflows you can use: HTTPS with tokens or SSH with SSH keys
    • [EDIT] Do workflows require different setups?

HTTPS Set-up

Step 1:
Create designated directories for your work account git repositories and your personal account git repositories. Think of it as one directory for all your work account repositories, and a second directory for all your personal account repositories. We'll use these directories in a later step, but first let's check for a .gitconfig file.

In this example, the directory names are: git_work and git_personal

Step 2:
Open a terminal window and check for a .gitconfig file (navigate to your home directory ~ and check using ls -a)

If you don't see a .gitconfig file create one using touch .gitconfig

In this file, you will see default user name and user email information.

What we want to do next is to add a conditional that will use a particular GitHub account configuration file depending on the filepath. If the filepath doesn't match, use the default account configuration.

To do this, we need to do two things:

a. Make another .gitconfig file, but make it specifically for the non-default account. In this case, we'll designate our work account as our non-default account. So let's navigate to our home directory and make the new file: touch .gitconfig-work.

Before moving to step b, let's add our work user information to the new file. To do this, open the file with the vim editor using vim .gitconfig-work. Then press a to activate edit more and add your work account information:

[user]
	name = workUsername
	email = workEmail@nceas.ucsb.edu

Press esc and write save quit file using :wq

Now we have two .gitconfig files: one for our personal user information as the default and one for our work user information

b. Now, let's navigate back into our default .gitconfig file and add an include statement (note this has to be wrapped in square brackets). Open the file using vim .gitconfig_work. Press a and add the following code:

[includeIf "gitdir:~/git_work/"`]
    path = ~/.gitconfig_work

This tells RStudio

HTTPS Workflow with (after set-up)

Resources

How to Use Multiple Git Configs on One Computer
MEDS Installation: MacOS

Clone this wiki locally