Featured image of post Git 指令

Git 指令

常用 Git 指令汇总

配置教程

首先绑定账号,namexxx@qq.com 分别是你的 GitHub 用户名和默认邮箱地址

git config --global user.name "name"
git config --global user.email "xxx@qq.com"

完成后可以使用以下命令进行查看

git config --global --list

接着生成ssh密钥文件

ssh-keygen -t rsa

然后连敲三次回车键

生成ssh密钥

然后到 C:\Users\.ssh 可以看到.ssh文件

找到 id_rsa.pub,用记事本打开,复制一下里面的内容,待会要用到。

来到GitHub,添加新SSH。

New SSH key

title随便写,key填写刚才复制的内容

填写内容

然后在git bash命令行输入

ssh -T git@github.com

中间还需要输入一次yes

💡如果出现以下情况,说明端口号被占用,使用以下代码即可

无法连接

ssh -T -p 443 git@ssh.github.com

完成

常用命令

初始化仓库,在目录中创建新的 Git 仓库

git init

从github拷贝源代码到本地文件夹

git clone [url]

查看远程仓库

git remote -v

移除远程仓库

git remote rm origin

添加当前目录的所有文件到暂存区

git add .

提交更改

git commit -m [message]

列出所有分支

git branch

查看配置信息

git config --list

修改代理

git config --global http.proxy 127.0.0.1:7890 && git config --global https.proxy 127.0.0.1:7890

取消代理

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

查看代理

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

设置拉取时只能快进合并

git config --global pull.ff only

参考文档

🔗 链接

Licensed under CC BY-NC-SA 4.0