跳转至

Git常用指令

1 基础

Bash
git init

添加某个文件到暂存区

Bash
git add <filename>

添加所有文件到暂存区

Bash
git add .

提交暂存区所有文件到仓库

Bash
git commit -m "<log messages>"

提交暂存区中指定文件到仓库

Bash
git commit <file1> <file2> ... -m "<message>"
Bash
git pull
Bash
git push
Tips

在一些特定的场景下,例如宝塔的服务器中,git pull可能会出现没有权限的情况,这种时候可以尝试把--globle修改为--system并设置安全组。原理暂时还不清楚。

2 邮箱和用户名

用户名

Bash
git config --global user.name "<username>"

邮箱

Bash
git config --global user.email <email@qq.com> 

用户名

Bash
git config user.name

邮箱

Bash
git config user.email

3 远程仓库

Bash
git remote -v
Bash
git remote set-url origin https://cangku.git
Bash
git remote add origin https://cangku.git
Bash
git remote rm origin