git 常用命令小结
· 阅读需 4 分钟
用了一段时间,把 git 的常规命令熟悉了一遍,稍微整理出来,方便后续查阅。
git 配置
全局配置文件位置:
~/.gitconfig
或~/.config/git/config
文件 项目配置文件位置:.git/config
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
# 配置默认编辑器
git config --global core.editor emacs
# 检查配置信息
git config --list
远程仓库
# 罗列远程仓库名(默认只有origin一个)
git remote
# 详细罗列远程仓库
git remote -v
# 查看远程仓库分支信息
git remote show origin
# 远程仓库重命名
git remote rename pb paul
# 移除远程仓库
git remote rm pb
# 添加远程仓库
git remote add pb https://github.com/paulboone/ticgit
# 拉取远程仓库
git fetch # git fetch origin
# 推送远程仓库
git push # git push origin master
仓库建立
# 获取远程仓库代码
git clone git://git.kernel.org/pub/scm/git/git.git
# 本地初始化仓库
git init