Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Last active July 20, 2022 02:38
Show Gist options
  • Save ryuheechul/bc8a6c32f7a50bde183d1b61dbf71867 to your computer and use it in GitHub Desktop.
Save ryuheechul/bc8a6c32f7a50bde183d1b61dbf71867 to your computer and use it in GitHub Desktop.
Note about Git and Github

Change Author

https://www.git-tower.com/learn/git/faq/change-author-name-email/

A Quicker Way via git-filter-repo

copied from https://stackoverflow.com/a/60364176/1570165

git-filter-repo \
  --name-callback 'return name.replace(b"OldName", b"NewName")' \
  --email-callback 'return email.replace(b"[email protected]", b"[email protected]")'

But this will do git remote rm origin though as mentioned here, newren/git-filter-repo#46 (comment).

So having these alias might be handy like below.

alias before-fix-email='git remote rename origin not-origin'
alias after-fix-email='git remote rename not-origin origin'
alias fix-git-email="git-filter-repo --email-callback 'return email.replace(b\"[email protected]\", b\"[email protected]\")'"

And you could use like this.

before-fix-email
fix-git-email -f
after-fix-email
# and of course you could combine all these into one alias/function as you wish

Different User per Directory (recursive)

copied from https://stackoverflow.com/a/43884702/1570165

[includeIf "gitdir:~/company_a/"]
  path = .gitconfig-company_a
[includeIf "gitdir:~/company_b/"]
  path = .gitconfig-company_b

and also https://blog.hao.dev/how-to-use-different-git-emails-for-personal-and-work-repositories-on-the-same-machine

Add Multiple Submodules At Once (via SSH)

cat <<EOF | xargs -I _ echo [email protected]:_.git | xargs -I _ git submodule add -b main _
github/.github
github/gitignore
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment