Git

Git 技巧

Posted by ZYT on January 18, 2019

1、将本地仓库同步到远程

    graph TD;
        A(git init) --> B(git add .);
        B(git add .) --> C(git commit -m message);
        C(git commit -m message) --> D(git remote add origin url);
        D(git remote add origin url) --> E(git pull origin master --allow-unrelated-histories);
        E(git pull origin master --allow-unrelated-histories) --> F(git push --set-upstream origin master);

2、协同开发,解决冲突

> git branch
* new_feature
  dev
  
> git checkout dev

> git pull --rebase
## 如果与远程发生冲突

> 修改冲突部分代码

> git add -u

> git rebase --continue);

> git checkout new_feature
> git rebase dev
> git checkout dev
> git merge new_feature
> git push

3、pull request

    graph TD;
        A(FORK project) --> B(git clone project);
        B(git clone project) --> |git remote add <name> <url>| C(添加上游仓库);
        C(添加上游仓库) --> |git pull --rebase <remote> <branch>| D(保持与上游仓库的同步);
        D(保持与上游仓库的同步) --> |git push --set-upstream <remote> <branch>| E(生成新的特征分支);
        E(生成新的特征分支) --> F(push);