My Own Git Notes


Posted by starwavelin on June 8, 2019

Useful Commands

  • $ git commit -n
    $ git commit -n, the -n is not a supported argument, if you look into But my company uses it to do enforced es-linting on staged files only. It is quite useful when there are some linting rule changes and you just want to apply es-linting on staged files that appearing after issuing command git merge <branch>.
    $ git commit -n -m 'brought master branch in'

    Explanation: -n is the enforcing es-linting on staged files only and -m is for issuing commit message.

  • $ git revert <certain_commit_hash>
    This will undo the changes in the “certain_commit_hash” but preserve the changes before and after the “certain_commit_hash”.

Generating New SSH Key Pair

Please read here.
When you need to clone and work on a project in a new machine, and you use SSH key pairs as you r way of authentication, you would want to generate a new SSH key pair. Basically, the link above uses GitLab as an example, but it should be similar to do it in GitHub.

How could I specify multiple users for myself in gitconfig?

Assume you have a default username and user email and a customized username and user email for GitHub. Then, you can specify when to use what as following:

  • For your default user / email, please configure them in your ~/.gitconfig
    git config --global "Your Default Name Here"
    git config --global
  • For an individual repo that you want to use your customized user / email address, which overrides the global configuration, please, from the root of the specified repo, run
    git config "Your Customized Name Here"
    git config