published on 28.05.2022

Each git commit has a field called Author which consists ‘user.name’ and ‘user.email’. We usually set these variables once, after installing git, with git config --global so that each repo gets the variables from the global definition. We can also set them locally for a specific repo without using the --global keyword. Global configs can be found at ~\.gitconfig and local config path-to-repo\.git\config.

Partial Configurations

Sometimes you may need to set up different email/user.name for different repos. Usually when working on both personal and work projects in the same computer. In that case, you may choose configure email and username manually for each repo but this is boring and open to errors. Luckily, there is a better way.

  1. Add as many gitconfig as you need: ~\.gitconfig-work, ~\.gitconfig-github etc.
  2. Define configurations in these partial config files.
[user]
  email = 43188411+mertbakir@users.noreply.github.com
  1. Then in the main config at ~\.gitconfig, define which partial configuration will be applied to which directory.
[includeIf "gitdir:Desktop/projects/work"]
  path = .gitconfig-work
[includeIf "gitdir:Desktop/projects/github/"]
  path = .gitconfig-github

Private Commit Email

Git services like GitLab and GitHub is using the email you’ve configured in your account settings and the email on the commits to link a commit with your account. So the email address we use for commits is important. What happens if we don’t want to use that email anymore or what if we don’t the email adress to be public. In this case we can use a non-reply commit e-mail. Both GitLab and GitHub provides such feature.

Edit Email for Previous Commits

If you want to edit email address for the previous commits this means you’ll overwrite the git history. In other words, the commit hashs will be different after the process. So, you’ll need to use git push --force. I suggest creating a test repo and test it safely.

Add the line below to ~\.gitconfig

[alias]
  change-commits = "!f() { VAR=$1; OLD=$2; NEW=$3; shift 3; git filter-branch --env-filter \"if [[ \\\"$`echo $VAR`\\\" = '$OLD' ]]; then export $VAR='$NEW'; fi\" $@; }; f"

Then use:

git change-commits GIT_AUTHOR_EMAIL "old_email_address" "new_email_address_here"

You can also use it change other properties like GIT_AUTHOR_NAME. One good thing is, this process won’t change the commit date only the property you’ve passed.

If you get an error like ‘backup already exists’, you may use: git update-ref -d refs/original/refs/heads/master.

The solution is from stackoverflow. I recently used this method and wanted to take note.

Published on 28.05.2022 by Mert Bakır with commit ef744b2.
random
published on 25.05.2022

In this post, I’ll first walk through hosting static content with basic authentication. Then, we’ll look into deploying to Heroku using GitLab Pipelines, more specifically deploying a certain sub-directory within the project instead of pushing the whole project. Also, I’ll share …

published on 17.04.2022
edited on 02.05.2022

Önceki bölümde, markdown formatını LaTeX formatına dönüştürmek için kullanılan Pandoc yazılımından bahsetmiştik. Şimdi konuyu bir adım daha ileri taşıyıp ve bookdown’a geçiyoruz. Bookdown; Rmarkdown kullanarak teknik dökümanlar, kitaplar yazabilmemizi sağlayan, Yihui Xie tarafından yazılmış …

published on 10.04.2022

I’ve been using WSL-2 on Windows for over a year. It’s very useful because some Python packages are just a headache to install on Windows. Also, docker. It’s just better on Linux. Yet, WSL-2 can also be problematic. I remember trying a dual-boot setup when things just went way too …

published on 03.03.2022

In this post, I’ll share how to install geopandas and some other gis related packages on Windows. If you are on Mac or Linux you can probably just pip install those without any issue. I usually had to do a google search every time I wanted to install these packages on Windows environment. Of …

published on 19.02.2022

Önceki yazıda LaTeX kullanmanın avantajlarından ve zorluklarından bahsetmiştim, MS Word gibi WYSIWYG programlar ile karşılaştırıp tavsiyelerimi yazmıştım. Bu yazıda Pandoc yazılımı üzerine konuşacağız. Pandoc’un da yardımıyla LaTeX’in avantajlarını alıp zorluklarını biraz geri de …