Commit and push to multiple Git accounts on the same computer?

I use GitHub for my personal projects.

I love GitHub.

My portfolio, my Spring Boot project, my Django project… Any personal practice is on my GitHub. (Here.😉)

However, I use GitLab at work.

And sometimes I want to practice some tools and technologies that I need to learn at work but want to commit and push on my personal (GitHub) account on my work laptop!!

How can I manage and use multiple git accounts on the same computer?

Here is what I’ve done and leave this a quick note to myself.

Today’s goal!

Again, here is what I wanted to do:

  • Main git account: GitLab (work)
  • Sub git account: GitHub (Personal)

And my file directory structure is like this;

1. Setup my main git account

— Use git config global.

I think this is already set up when you build your local environment.

This will be your main git account, so set it globally.

$ git config --global user.name "<main account username>"
$ git config --global user.email "<main account email>"

To check if it’s applied, you run;

$ cat ~/.gitconfig[user]
email = <main account email>
name = <main account username>

2. Setup my sub git account

— Use git config local, set each repository.

To set up your personal git account, you need to set it by a repository.

And set those configs in <repository>/git/config .

First, clone your personal repo and move to the repo.

$ cd practice/personal_project
$ git config --local user.name "<sub account username>"
$ git config --local user.email "<sub account email>"

To check if it’s applied, you run;

$ cat .git/config                               
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/yuki-nagano/personal_project.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
[user]
name = <sub account email>
email = <sub account email>

You’re all set!

Now you can commit and push with your main/sub account separatedly!

--

--

--

Back-End Engineer, Software Engineer | Python, Java, JavaScript | Green Card Lottery (DV-2020) Winner

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Moving towards Continuous Delivery

How to create a Language Learning Application?

The Complete Guide to Use Docker Compose

what happens when you type https://www.holbertonschool.com in your browser and press Enter.

Configuring SSH Key for Git

Creating a UI Display Bar for Thrusters in Unity3D

Databases with Python

Remove Bottlenecks with Proper Asset Management

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yuki Nagano

Yuki Nagano

Back-End Engineer, Software Engineer | Python, Java, JavaScript | Green Card Lottery (DV-2020) Winner

More from Medium

Version Control with Git

Setting up Electron and Building for Linux in Ubuntu 20.04LTS

Docker in simple words

GitHub vs GitLab