项目作者: ijklim

项目描述 :
Project to test git flow with multiple users
高级语言:
项目地址: git://github.com/ijklim/git-multi-users-pull-request.git
创建时间: 2018-05-03T13:31:18Z
项目社区:https://github.com/ijklim/git-multi-users-pull-request

开源协议:

下载


Project to test git flow with multiple users

Setup

  • Users: desktop, laptop
  • Branches: master, desktop, laptop

Step 1

  • desktop create README.md file and create first commit: ‘Initial Commit’
  • desktop push to master

    git push --set-upstream origin master

  • This should be the first and last time commit is directly pushed to branch origin/master

  • Protect branch master by enabling ‘Require pull request reviews before merging’
  • Add laptop user as Collaborator
  • Create and switch to branch desktop

    git checkout -b desktop

  • Create 2 files with 3 lines each: people.md, cars.md

  • Commit the 2 files as ‘#desktop - create new files: people and cars’
  • Push to origin

    git push --set-upstream origin desktop

  • Create pull request ‘#desktop - create new files: people and cars’

Step 2

  • laptop accept collaborator invitation
  • Clone remote repo

    git clone git@github.com:ijklim/git-multi-users-pull-request.git

  • Create and switch to branch laptop

    git checkout -b laptop

  • Create 2 files with 3 lines each: people.md, fruits.md

  • Commit the 2 files as ‘#laptop - create new files: people and fruits’
  • Push to origin

    git push --set-upstream origin laptop

  • Create pull request ‘#laptop - create new files: people and fruits’

Step 3

  • desktop approves pull-request from laptop ‘#laptop - create new files: people and fruits’
  • desktop merge pull-request into branch master
  • Status of pull-request ‘#desktop - create new files: people and cars’ changes

  • Commit screenshots and README.md changes to branch desktop as ‘#desktop - add screenshots and update README’
  • Switch to master, pull from remote origin

    git checkout master
    git pull

    Result:

    1. Updating 2471afd..6e0febc
    2. Fast-forward
    3. fruits.md | 3 +++
    4. people.md | 3 +++
    5. 2 files changed, 6 insertions(+)
    6. create mode 100644 fruits.md
    7. create mode 100644 people.md

    git log --oneline

    Result:

    1. 6e0febc (HEAD -> master, origin/master) Merge pull request #2 from ijklim/laptop
    2. c94164a (origin/laptop) #laptop - create new files: people and fruits
    3. 2471afd Initial commit
  • Switch back to desktop and attempt to pull changes from local master

    git checkout desktop
    git log --oneline

    Result:

    1. a4d8c19 (HEAD -> desktop) #desktop - add screenshots and update README
    2. 41f3b80 (origin/desktop) #desktop - create new files: people and cars
    3. 2471afd Initial commit

    git merge master

    Result:

    1. Auto-merging people.md
    2. CONFLICT (add/add): Merge conflict in people.md
    3. Automatic merge failed; fix conflicts and then commit the result.
  • With merge conflict, cancel merge and use rebase instead

    git merge --abort
    git merge rebase master

    Result:

    1. First, rewinding head to replay your work on top of it...
    2. Applying: #desktop - create new files: people and cars
    3. error: Failed to merge in the changes.
    4. Using index info to reconstruct a base tree...
    5. Falling back to patching base and 3-way merge...
    6. Auto-merging people.md
    7. CONFLICT (add/add): Merge conflict in people.md
    8. Patch failed at 0001 #desktop - create new files: people and cars
    9. The copy of the patch that failed is found in: .git/rebase-apply/patch
    10. Resolve all conflicts manually, mark them as resolved with
    11. "git add/rm <conflicted_files>", then run "git rebase --continue".
    12. You can instead skip this commit: run "git rebase --skip".
    13. To abort and get back to the state before "git rebase", run "git rebase --abort".
  • Fix conflict in file people.md and continue

    git add people.md
    git rebase --continue

  • Push to remote desktop, use flag —force to override

    git push --force

Step 4

  • laptop approve pull-request ‘#desktop - create new files: people and cars’
  • laptop merge pull-request ‘#desktop - create new files: people and cars’
  • Switch to master, pull changes from remote origin

    git pull
    git log --oneline

    Result:

    1. f9edf4b (HEAD -> master, origin/master, origin/HEAD) Merge pull request #1 from ijklim/desktop
    2. 73d8382 (origin/desktop) #desktop - add screenshots and update README
    3. a0f435d #desktop - create new files: people and cars
    4. 6e0febc Merge pull request #2 from ijklim/laptop
    5. c94164a (origin/laptop, laptop) #laptop - create new files: people and fruits
    6. 2471afd Initial commit
  • Switch to laptop and pull changes from master

    git checkout laptop
    git log --online

    Result:

    1. c94164a (HEAD -> laptop, origin/laptop) #laptop - create new files: people and fruits
    2. 2471afd Initial commit

    git merge master
    git log --online

    Result:

    1. f9edf4b (HEAD -> laptop, origin/master, origin/HEAD, master) Merge pull request #1 from ijklim/desktop
    2. 73d8382 (origin/desktop) #desktop - add screenshots and update README
    3. a0f435d #desktop - create new files: people and cars
    4. 6e0febc Merge pull request #2 from ijklim/laptop
    5. c94164a (origin/laptop) #laptop - create new files: people and fruits
    6. 2471afd Initial commit

Conclusion

  • All branches are now all in sync