Git 常用命令
介绍Git相关的各种命令
相关应用推荐
Git官网下载:https://git-scm.com/downloads
Git项目管理工具推荐:GitKraken(Note: github的private不能免费用)
Git项目平台:GitHub (https://github.com/)
Workflow
建立本地仓库
- git init #创建一个初始化仓库
- git clone #将远程仓库代码克隆到本地
git基本用法
- git add #将changes放到stage中
其中,git add . #将目录下所有文件放到stage中;git add *.py #添加所有的python类型的文件 - git commit -m “xxx” #将stage中的改动提交到本地仓库
- git pull #同步远程仓库的代码到本地,并准备解决冲突
- git push origin master #将本地仓库的代码改动放到远程仓库分支
其中,git push origin xxx:xxx #将本地的xxx分支的代码改动放到远程仓库的xxx分支
远程仓库命令
- git remote add [shortname] [url] #添加远程仓库
- git remote show [shortname] #查看远程仓库信息
- git remote rename [old-name] [new-name] #重命名远程仓库
- git remote rm [shortname] #删除远程仓库
分支操作
- git branch -a #查看所有分支
- git branch [new-branch] #基于当前分支新建一个分支,当保持在当前分支
- git branch -b [new-branch] #基于当前分支新建一个分支,并切换到该分支
- git checkout [branch-name] #切换到指定分支,并更新工作区
- git merge [branch-name] #merge指定分支到当前分支
- git branch -d [branch-name] #删除指定分支
- git push origin --delete [branch-name] #删除远程分支
特殊场景
- 删除远程仓库文件或文件夹,本地保留
- git rm -r --cached myfile(要删除的文件)
- git commit -m “comment”
- git push
注意:要在.gitignore中过滤掉该文件