Git基础
Git基础
一点点基础,应该够给你搭博客使用了
基础
git help 查看帮助
git help [子命令]
最重要的命令,查看帮助。
git config 设置
在提交之前,你必须先设置你的名字和 email。这是你在提交 commit 时的签名,每次提交记录里都会包含这些信息。
git config --global user.name "YourName"
git config --global user.email "YourEmail@xxx"
--global
是全局设置,仓库中单独设置信息要将其去掉。
本地操作
git init
Git初始化,在目标目录内执行
git status
检测当前目录和暂存区的状态
git add
将要同步的内容加入本地暂存区
git add [目录/文件]
常用
git add .
将当前目录下所有改动添加到暂存区
git add -A ## 将仓库所有改动添加到暂存区
git commit
提交到本地仓库中,后面加注释
git commit -m "注释"
git commit -am "注释" ## 相当于同时执行了 git add -A
git commit 提交信息参考规范:Angular
远程仓库
git clone
克隆一个Git仓库到本地,可以将仓库内容直接下载下来,默认会关联远程仓库。
git clone <url>
git remote 管理远程仓库
查看远程仓库
git remote -v [show] # 查看远程仓库
-v
:详细输出
git remote show <远程仓库名称> # 查看某个远程仓库信息
常用
git remote add <远程仓库名称> <仓库url> # 与远程仓库添加关联
git remote remove/rm <远程仓库名称> <仓库url> # 与远程仓库移除关联
git remote rename <远程仓库名称> # 重命名远程仓库
git push
将本地仓库内容推送到远端仓库中
git push <远程仓库名称> <本地分支>:<远程分支>
git push <远程仓库名称> <本地分支> ## 分支名称相同可简写
git push <远程仓库名称> ## 推送当前分支可简写
-f
:强制推送
-u
:同时建立分支的关联,一般用于手段添加 remote
git pull
从远程仓库拉取到本地仓库,与git push
相反
git pull <远程仓库名称> <远程分支>:<本地分支>
git pull <远程仓库名称> <远程分支> ## 分支名称相同可省略
git pull <远程仓库名称> ## 推送当前分支可简写