Managing multiple Git profiles

Managing multiple Git profiles

Learn how to configure git to use the appropriate email address (and other user fields) based on your current project directory. If you use git as the version control tool for both your personal projects and at work, chances are that you want to isolate the two (or more) profiles, i.e. at the very least, using different emails for creating commits and tags. Other uses might include using different usernames (for different GitHub accounts), gpg-keys, etc.

What if Git already knew whether to use your work email or personal? Say no more. Here's how.

If you use git as the version control tool for both your personal projects and at work, chances are that you want to isolate the two (or more) profiles, i.e. at the very least, using different emails for creating commits and tags. Other uses might include using different usernames (for different GitHub accounts), gpg-keys, etc.

One straightforward way of tackling this is to remember setting the correct configuration whenever you clone (or initialize) a new repo:

git config user.name "priam"
git config user.email "[email protected]"

Besides, being painstakingly mundane, it is yet another thing to remember. Nevermind the time and effort of rewriting history if you have already created commits.

But wait, there’s a better way

Git offers a much more flexible way of specifying conditional config files based on your current directory — if you use a different directory for all your work repos (let’s say ~/work/), then you can specify the following in your ~/.gitconfig to automatically use your work credentials inside them:

[include]
    path = ~/git-personal.conf
[includeIf "gitdir:~/work/"]
    path = ~/git-work.conf

Each conf file can then define it’s own user, e.g. ~/git-personal.conf:

[user]
    name = realerlich
    email = [email protected]
    signingkey = FF5353EC154B6811

and ~/git-work.conf:

[user]
    name = erlich
    email = [email protected]
    signingkey = CE3454AA132E6F2E

There, all set now! Whenever you are working inside a repo that lives under ~/work, Git will automatically use your work email. Go ahead, try it out!

git managing git profiles

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Best Practices for Using Git

Git has become ubiquitous as the preferred version control system (VCS) used by developers. Using Git adds immense value especially for engineering teams where several developers work together since it becomes critical to have a system of integrating everyone's code reliably.

7 Best Practices in GIT for Your Code Quality

Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Check out 7 best practices for Git.There is no doubt that Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Still, developers struggle for code quality.

Git Rebase Tutorial and Comparison with Git Merge

In this article, I will explain to you a few differences between git merge, git rebase, and the git interactive rebase.I will tell a bit about what pros...

Digital Assets Management Software Solution | AI-based Assets Management System

Digital Assets Management Software helps an organization or business to upload, store, organize, manage, share, and track digital assets in one place. Our AI-based Assets Management System allows companies to unite their asset data on the intelligent blockchain network.

Mirroring Git Changes From One Server to Another Server

Hello all, nowadays most of the development teams using GIT version control, some of you may have a requirement of mirroring your team's git changes from one server to another Git server. This article will help you to achieve the Git mirroring between one server to another server.