Git bash 使用
Git安装
安装Git时在勾选组件项,只需勾选Git Bash Here
,其他一路next即可。
初始化本地库
在本地新建文件夹作为本地库位置,右键 ——》Git Bash Here 打开bash命令行
设置用户
1 2
| git config --global user.name "Your Name" git config --global user.email "Your Email"
|
检查本机密钥
- 如果电脑上已经存在密钥,就会显示…/.ssh: Is a directory
- 如果电脑上没有密钥,那就显示…/.ssh: No such file or directory
- id_rsa.pub —— 公钥
- id_rsa —— 私钥
如果本机没有密钥,需要生成密钥:
1
| ssh-keygen -t rsa -C "Your Email"
|
配置密钥
在GitHub上的 个人中心 —— settings —— SSH and GPG keys —— New SSH key 配置密钥,Title随意填,key填本机公钥的全部内容。
常用命令
1 2 3 4 5 6 7 8 9
| git status git add git commit -m "new commit" git branch -M DDY-master git remote add origin git@github.com:WineMonk/DDY.git git push -u origin DDY-master git clone git@github.com:WineMonk/DDY.git git pull 仓库名称 git fetch + git merge
|
其中 git add
命令有很多
1 2 3 4 5 6 7 8
| git add +文件名.文件类型 git add +文件名.文件类型 ... 文件名.文件类型 git add xx文件夹/*.html git add *hhh git add Hello* git add -u git add . git add -A
|
其他
Git global setup
1 2
| git config --global user.name "邵智远" git config --global user.email "shaozy@geoscene.cn"
|
Create a new repository
1 2 3 4 5 6 7
| git clone http://git.esrichina.com.cn/new-fundamental-surveying-and-mapping/rs3.git cd rs3 git switch -c main touch README.md git add README.md git commit -m "add README" git push -u origin main
|
Push an existing folder
1 2 3 4 5 6
| cd existing_folder git init --initial-branch=main git remote add origin http://git.esrichina.com.cn/new-fundamental-surveying-and-mapping/rs3.git git add . git commit -m "Initial commit" git push -u origin main
|
Push an existing Git repository
1 2 3 4 5
| cd existing_repo git remote rename origin old-origin git remote add origin http://git.esrichina.com.cn/new-fundamental-surveying-and-mapping/rs3.git git push -u origin --all git push -u origin --tags
|