Skip to content

Git

how to check if a key being used by an account

ssh -T -ai ~/.ssh/id_rsa git@github.com   

generate a key pair for each github account on every machine

ssh-keygen -t rsa -C “your-email-address”     
create a new key file name: /c/Users/your_username/.ssh/id_rsa_yourAccountname     
cp the pub key file content from ~/.ssh/id_rsa_yourAccountname.pub to github account

change git config, and make it use the new key pair

git config -e     
add below line to [core]   
"sshCommand = ssh -i ~/.ssh/id_rsa_yourAccountname"

configure user and email

git config user.name "xxx"    
git config user.email "xxx@xxx"

if encount follow error, remore the remote repo and readd

ERROR: Permission to user/repo-git.git denied to anotherUsername      

git remote rm github      
git remote add github git@github.com:username/xxx.git     
git push -u github master

git commands

https://gist.github.com/cobyism/4730490

git add .     
git commit -m "xxx"     
git push

git subtree push --prefix site origin gh-pages (tochk)

.gitignore

foo/ match a directory `foo` and paths underneath it
hello.* matches any file or folder whose name begins with hello
foo/* matches "foo/test.json" (a regular file), "foo/bar" (a directory) but not "foo/bar/hello.c"

remove a folder after adding to .gitignore

git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master

remove history commit

git reset --hard HEAD~2 (remove last 2 commit)
git push -f

remove sensitive data from history

$ git filter-branch --force --index-filter "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" --prune-empty --tag-name-filter cat -- --all
$ echo "YOUR-FILE-WITH-SENSITIVE-DATA" >> .gitignore
$ git add .gitignore
$ git commit -m "Add YOUR-FILE-WITH-SENSITIVE-DATA to .gitignore"
$ git push origin --force --all

create an empty branch

git clone git@github.com/<user>/<repo>.git

git checkout --orphan <empty-branch>
git rm -rf .
git commit --allow-empty -m "init"
git push origin <empty-branch>

connect different folder to different github account