Home > Enterprise >  Wrong credentials approved by git
Wrong credentials approved by git

Time:07-12

So I needed to add my personal GitHub account to my office laptop in which I was already using my work github account. So I created a separate ssh key and stored that into a separate file. I added that newly created ssh to my personal github account.

Then I added a config file like this:

Work
   Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa
   
 Personal account
   Host github.com-personal  
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_personal

I then created a PRIVATE new repository in personal git repository and cloned it like the following so that it will use personal ssh token:

git clone [email protected]:prajatpadhi/udemy-react-maximillian.git

I then made some commits and pushed. But I was surprised to see that the commit's author was my work's userid because I had forgotten to change the username and email of my local repository.

But shouldn't in such a case there should be an authorization error as the repository was private in the personal git hub account. How did GitHub allowed access?

My personal userid is lets say pp and work's pp1. How can pp1 be allowed to push a commit to pp's private repository?

CodePudding user response:

Here is a simple, but basically untested, pre-push hook that can check for commits made with user.name and/or user.email settings that you don't want. Modify the check() function as desired.

#! /bin/sh
#
# pre-push hook to check commits to be sent
#
# The check() function takes a commit hash ID and decides if it's OK
# (returns zero) or not (returns nonzero).
check() {
        local hash="$1" ret=0
        set -- $(git log --no-walk --pretty=format:"%an            
  • Related