[Git] How to Resolve Conflict?

Judy·2023년 1월 1일
0

Dev

목록 보기
2/7
post-custom-banner
  • 깃허브 사용 중 Conflict 발생 시 해결방법.
  • 노션에 작성한 내용을 옮겼더니 템플릿이 깨짐. 아래의 Notion 링크 참조.
  • Notion template is better than velog post,
    so you'd better visit here for the same content :
    (Notion) How to Resolve Conflict?

If user changed the same line in the different branch & merge into the same branch(ex. main), conflict can occur.

1. Initialize & Clone

  1. Create Github Repository

  2. Create Local Repository

    mkdir git-practice
  3. Clone

    
    cd git-practice/
    git clone https://github.com/wecode-bootcamp-korea/wecode-git-test.git
  4. Remove remote connection

    1. Move into cloned repository’s directory
    2. Remove remote connection between ‘wecode-bootcamp-korea/wecode-git-test’ repository
    
    cd wecode-git-test/
    git remote remove origin
  5. Remote my own repository ‘Judy-Choi/git-practice’

    
    git remote add origin https://github.com/Judy-Choi/git-practice.git
  6. Create Main Branch & Push

    Follow the Github repository’s direction

    
    cd Backend/
    git branch -M main
    git push -u origin main

    Github Repository

[main] app.js

2. Branch Task

2-1. [main] → [feature/signup]

  1. Create new branch [feature/signup] from [main] & move into.


    git branch feature/signup
    git checkout feature/signup
  1. Add signup code to app.js

    [feature/signup] app.js

  2. add & commit & push (pull request)

    
    git add .
    git commit -m "Commit message"
    git push origin feature/signup
  3. Create Pull Request on Github

2-2. [main] → [feature/signin]

  1. Create new branch [feature/signin] from [main] & move into.

    
    # Return to main
    git checkout main
    
    # Create new branch
    git branch feature/signin
    git checkout feature/signin

    [feature/signin] app.js

    Because I returned to [main] branch & create [feature/signin],

    added codes in [feature/signup] are not here. (= same as [main])

  2. Add signin code to app.js

[feature/signin] app.js
  1. add & commit & push (pull request)

    
    git add .
    git commit -m "Commit message"
    git push origin feature/signin
  2. Create Pull Request on Github

3. Conflict

3-1. Merge [main] ← [feature/signup] on GitHub

Conflict occured in [feature/signin]!

(In another branch (not merged yet), conflict is occured)

3-2. Resolve Conflict

  1. Return to local [main] branch & Pull from remote [main] branch

    
    git checkout main
    git pull origin main
  2. Merge [feature/signin] ← [main]

    
    git checkout feature/signin
    git merge main 
  3. Check the conflict & Save app.js

    [feature/signin] app.js

  4. add & commit & push (pull request)

    
    git add .
    git commit -m "commit message"
    git push origin feature/signin

    Resolved!

    Now [feature/signup] & [feature/signin] are in [main].

profile
NLP Researcher
post-custom-banner

0개의 댓글