记录下自己git命令
Git 全局设置:
git config --global user.name "your name"
git config --global user.email "your email"
查看全局配置
git config --list
创建 git 仓库:
mkdir hello
cd hello
git init
touch README.md
git add README.md
git commit -m "first commit"
origin:远程仓库名称(可以修改)
git remote add origin git@gitee.com:xiefeichn/hello.git
git push -u origin master
已有仓库?
cd existing_git_repo
git remote add origin git@gitee.com:xiefeichn/hello.git
git push -u origin master
拉取远程服务器 指定分支
远程仓库orgin, 远程分支feature-20200709, 本地master分支
$ git pull origin feature-20200709:master
推送代码 到远程指定分支
origin 远程仓库, feature-20200709 远程分支(这是709版本),master本地master分支
$ git push origin master:feature-20200709
如果push失败
! [rejected] master -> feature-20200709 (fetch first)
error: failed to push some refs to 'git@gitee.com:xiefeichn/flink-test.git'
先pull,在push
$ git pull origin feature-20200709:master
查看本地当前分支,与origin/feature-20200709不同
$ git diff origin/feature-20200709
或者
origin远程仓库,feature-20200709远程分支
$ git fetch origin feature-20200709
文件冲突
远程分支 与 本地分支(master)冲突,无法提交、pull
1 检出远程的feature709分支,到本地 feature-20200709分支
$ git checkout -b origin/feature-20200709
2 合并本地feature-20200709,到本地master(冲突分支)
$ git checkout master
$ git merge origin/feature-20200709
3 修改冲突文件,并保存
类似下面的冲突
<<<<<
+++ddddd
>>>>
--aaaa
4 添加修改文件,并本地提交
$ git add people.txt
$ git commit -m "解决冲突文件"
5 解决了。本地正常编程提交
检出远程的feature-branch分支到本地
git checkout -b feature-branch origin/feature-branch