目录

GitHub

misaraty 更新 | 2022-01-11
前言
自己大部分代码都托管到Github上的PublicPrivate仓库上。

1 安装

下载Git

1.1 创建ssh key

安装Git过程中,默认Enter,打开Git Bash

1
ssh-keygen -t rsa -C "misaraty@163.com"

默认Enter,在C:\Users\m\.ssh下有id_rsa.pub文件,打开并复制key

1.2 在GitHub中关联key,

SettingsSSH and GPG keysNew SSH keys,输入key。在Git Bash中,

1
ssh -T git@github.com

输入yes,显示You've successfully authenticated, but GitHub does not provide shell access.

1.3 Git关联账号

1
2
git config --global user.name "misaraty"
git config --global user.email "misaraty@163.com"

2 新建远程仓库

Github网站右上角头像旁+号new repository。进入项目主页,clone https://github.com/misaraty/scripts.git

3 新建本地仓库

D:\anzhuang\git下打开Git Bash Here

1
2
git init
git clone https://github.com/misaraty/scripts.git

4 推送

1
2
3
git add -A
git commit -m "update"
git push
注意
  • 执行上述命令时,需在对应的文件夹下,如D:\anzhuang\git\scripts

  • 上述命令写法,考虑到了删除文件后的推送问题,即删除文件后推送依旧有效。

5 本地同步

1
git pull

6 一键操作

修改C:\Program Files\Git\etc\profile.d\aliases.sh1

1
2
3
4
alias gp='git pull'
alias ga='git add -A && git commit -m "update" && git push'
alias gc1='git checkout --orphan latest && git add -A && git commit -am "update" && git branch -D master && git branch -m master && git push -f origin master'
alias gc2='git checkout --orphan latest && git add -A && git commit -am "update" && git branch -D main && git branch -m main && git push -f origin main'
报错
1
2
3
4
5
6
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
    git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
    git branch --set-upstream-to=origin/<branch> master
解决
1
git branch --set-upstream master origin/master
报错

每次git push时需要输密码

解决
1
git config --global credential.helper store
报错
1
2
3
4
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean
解决
1
2
git push -u origin master #本地覆盖远程
git reset --hard origin/master #远程覆盖本地

7 代理

  • 查看配置列表
1
git config --list
  • 配置代理
1
2
git config --global http.proxy 'socks5://127.0.0.1:7890'
git config --global https.proxy 'socks5://127.0.0.1:7890'
  • 撤销代理
1
2
git config --global --unset http.proxy
git config --global --unset https.proxy
  • 查看代理
1
2
git config --global --get http.proxy
git config --global --get https.proxy
报错
1
Unsupported proxy syntax in '127.0.0.1:7890'
解决

打开.gitconfig文件,去掉单引号,

1
2
3
4
5
6
[http]
	sslBackend = openssl
	sslCAInfo = C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem
	proxy = socks5://127.0.0.1:7890
[https]
	proxy = socks5://127.0.0.1:7890

8 代码行数统计

1
git log --author="misaraty" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -

  1. how to delete all commit history in github? ↩︎