前提:本电脑已经安装了GIt插件,不会安装的请Google搜索Git安装
教程链接:(https://www.jianshu.com/p/414ccd423efc)
1:从没有提交过的新代码提交到新的远程仓库中
1.1 打开定位到代码的目录处
1.1.1 初始化代码
1 | $ git init |
1.1.2 新建本地分支
1 | $ git remote add [分支名] [Git仓库地址] |
2 | 样例: |
3 | $ git remote add origin https://github.com/xxxxx/xxxxx.git |
1.1.2.1 查看当前所有的分支
1 | $ git remote -v |
1.1.2.2 修改分支地址
1 | $ git remote set-url [修改的分支名] [Git仓库地址] |
2 | 样例: |
3 | $ git remote set-url origin https://github.com/xxxxx/xxxxx.git |
1.1.2.3 删除分支
1 | $ git remote remove [要删除的分支名] |
2 | 样例: |
3 | $ git remote remove origin |
1.1.3 提交代码到本地仓库中
1 | $ git add . |
1.1.3.1 提交到本地仓库时,可能会报的错误
1 | 错误样例: |
2 | warning: LF will be replaced by CRLF in pubspec.lock. |
3 | The file will have its original line endings in your working directory |
4 | 修复:命令行内输入 |
5 | $ git config --global core.autocrlf false |
1.1.4 提交代码信息
1 | $ git commit -m "[本次提交的信息]" |
2 | 样例: |
3 | $ git commit -m "第一次提交" |
1.1.5 提交代码到远程仓库中
1 | $ git push -u [远程分支名] [要提交的Git仓库分支] |
2 | 样例: |
3 | $ git push -u origin master |
其他
1.克隆Git代码到本地
1 | $ git clone [Git仓库地址] |
2 | 样例: |
3 | $ git clone https://github.com/xxxxx/xxxxx.git |
1.1 克隆指定分支的Git代码到本地
1 | $ git clone -b [Git分支] [Git仓库地址] |
2 | 样例: |
3 | $ git clone -b develop https://github.com/xxxxx/xxxxx.git |
2.拉取代码(注意冲突)
1 | $ git pull [分支] [Git分支] |
2 | 样例: |
3 | $ git pull origin master |