How to share Git aliases across multiple workstations?
Asked Answered
S

1

5

When using Git on multiple workstations, and for different Git repositories, it is convenient to have the same set of aliases available.

So, to synchronize the Git aliases across different workstations, and across different repositories, I consider putting the aliases in a shared Git repository on GitHub, but I am now certain how that can be done, or if that is the best way.

How to share Git aliases across multiple workstations?

Note: The answer at "Git aliases that are stored in origin" has some good input, but it does not directly address the question of how to share Git aliases across different Git repositories.

Spurling answered 3/6, 2021 at 18:36 Comment(4)
Does this answer your question? Git aliases that are stored in originAgglutinogen
Note you can put other useful configs in that shared config file too. (It doesn't have to be just aliases.) For example, add datetime and author to interactive rebase: rebase.instructionformat=(%an %ai) %sFieldstone
You could also share the .gitconfig file in your home directory.Optimism
@Matt: The question "Git aliases that are stored in origin" only partly answers my question, since my aliases are shared across different Git repositories, so it does not make sense to save the aliases in the project repository itself. I will update the question to reflect that.Spurling
S
0

Its possible with just maintaining shared global .gitconfig across multiple workstations!! It can be done easily by setting up alias4git on target workstations.

  1. Clone alias4git

    git clone https://github.com/pipelineinc/alias4git.git
    
  2. Update paths in file alias.gitconfig to appropriate path of cloned alias4git repository

  3. Use git cfg command to add new aliases instead of standard git config command

    for example,

    git cfg --add alias.st "status"
    
    git cfg --add alias.cm "commit -m"
    

    (Note that git cfg command modifies alias4git/alias.gitconfig instead of actually modifying global .gitconfig file !!)

  4. Commit and push your changes in alias4git/alias.gitconfig to alias4git repository

  5. Update alias4git/alias.gitconfig on all other workstations by syncing alias4git repository

    cd alias4git
    git pull
    

As alias4git/alias.gitconfig file now works as replacement for global .gitconfig, it works for all the git repositories, across multiple workstations and across multiple git users.

Hope this answers your question!

String answered 17/1, 2023 at 10:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.