GithubHelp home page GithubHelp logo

yannoff / su-git Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 27 KB

A simple tool to handle multiple git accounts on the same system

License: MIT License

Shell 93.30% Makefile 6.70%
git github gitlab ssh-key sudo

su-git's Introduction

su-git

A simple tool to handle multiple git accounts, using multiple SSH keys.

The reason

I ran into the problem when having to collaborate on 2 distincts github accounts simultaneously: my own account and the one I was running for my organization.

Here is the pitfall: each SSH key can be associated with one and only one account.

Unfortunately, git automatically takes the default key (typically $HOME/.ssh/id_rsa) for granted.

So creating a fresh new SSH key (let's say $HOME/.ssh/id_rsa2) and adding the corresponding public key to the repository was not enough to solve the problem.

Indeed, what git lacks is an option (like --identity on ssh command) to specify which private key should be used.

And here comes su-git!

Installation

First, clone the project into a temporary directory:

$ cd /tmp
$ git clone https://github.com/yannoff/su-git.git

Then, go inside su-git directory,

$ cd su-git

then run:

$ make
$ sudo make install

Now su-git can be called from anywhere on your system.

Usage

Prior to the first run of su-git, you need to configure which identity file will be used for the current dir:

$ git config ssh.identity /path/to/your/private_key

NOTE: su-git leverages the powerful git-config engine to store its ssh.identity option. This means you can configure a global setting for your private key, and override it on a per-project level, as you would do for any other regular git configuration value.

Now you can use su-git for push/pull operations, exactly the same way as git, having your identity handled automatically.

Example:

  1. Use su-git for cloning
$ su-git clone --identity ~/.ssh/your_rsa [email protected]:dummy/my-project.git

NOTE: When cloning, there is no .git folder in the current directory, so git config cannot be used here, even if a global setting exists for ssh.identity.

  1. Configure your identity file from inside the working dir
$ cd my-project
$ git config ssh.identity ~/.ssh/your_rsa
  1. Work locally using git
$ git checkout -b feature/my-awesome-feature
...
$ git add .
$ git commit -m "My commit"
...
  1. Use su-git when pushing your local branch
$ su-git push -u origin feature/my-awesome-feature

Note

This project was proudly pushed using su-git.

License

Licensed under the MIT License.

su-git's People

Contributors

yannoff avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

excloudx6

su-git's Issues

User unknown when stored in global config

For commands which issue a commit, for instance, su-git pull --rebase, a "who are you ?" git message raises.

This happens when no user is configured for the current project, even if the user is known in global config.

Should not mount userland config if it does not exist

Problem

If the userland config file - namely $HOME/.gitconfig does not exist, docker will create it as an empty directory to bind-mount it, which is not the desired behavior.

Solution

Only mount the user's git config file if it exists.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.