GitHub

1 下载Git

1.1 创建ssh key,

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

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

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

1.2 在GitHub中关联key,

Settings-SSH and GPG keys-New SSH keys,输入key。在Git Bash中,

ssh -T git@github.com

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

1.3 Git关联账号

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

2 新建远程仓库

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

3 新建本地仓库

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

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

4 推送

git add -A
git commit -m "update"
git push

a 执行上述命令时,需在对应的文件夹下,如D:\anzhuang\git\scripts;

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

5 本地同步

git pull

6 一键操作

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

alias gp='git pull'
alias ga='git add -A && git commit -m "update" && git push'
alias gc='git checkout --orphan latest && git add -A && git commit -am "update" && git branch -D master && git branch -m master && git push -f origin master'

how to delete all commit history in github

README写法参考

若遇以下报错,

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

则,

git branch --set-upstream master origin/master

若每次git push时需要输密码,则

git config --global credential.helper store

7 代理

配置代理

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

撤销代理

git config --global --unset http.proxy
git config --global --unset https.proxy

查看代理

git config --global --get http.proxy
git config --global --get https.proxy

8 代码行数统计

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 }' -