Git

Add SSH Keys

Create Repo

Clone

# 如果已经在记录了ssh key的机器上用
git clone [email protected]:lava-lake/llpub.git
# 在随便一台机器上获得public repo
git clone https://github.com/lava-lake/llpub.git

Config User

git config --global user.email "[email protected]"

Add a new file & commit

# get a file to local folder
 touch test.txt   

# check status
 git status

# add file to stage/buffer 
 git add test.txt

# commit changes
 git commit -m 'add test.txt'

# push changes
 git push

Edit & commit

# change file
echo 'new line' >> test.txt

# check status
 git status

# add file to stage/buffer 
 git add test.txt

# commit changes
 git commit -m 'added new line to test.txt'

# push changes
 git push

更新远端修改

git stash
git pull
git stash pop
# 可能有conflict,如果想保持本地修改(比如config.php),只更新其他
git checkout --theirs -- config.php
# 只选了本地的config.php的部分

rm

git rm file.txt
git rm -r folder
git commit -m 'rm a file & folder'
git push

国内机器使用Github的加速配置

Forked Repo怎么合并Original里面的更新

# 把forked repo先clone到本地
git clone [email protected]:lava-lake/py_scripts
# py_scripts was cloned from Arronlong/py_scripts
git remote add upstream [email protected]:Arronlong/py_scripts
# 如果搞错了可以通过 git remote remove upstream 然后再 add

# 更新upstream里面的修改
git pull upstream master

# if any conflict,比如在actions-textnow.yml 当中;fix first, then
git add .github/workflows/actions-textnow.yml
git commit -m 'fix conflict on workflows/actions-textnow.yml'

# 再push回去
git push origin master

# done

Git当中使用本地http代理

git config --global http.proxy 'http://127.0.0.1:17890'
git config --list

Leave a Reply