-1

Imaging you have made a branch from main and you add some features. The same time, your coworker has made a branch too and is working on it. If he merges his work to the master branch, how can you also merge yours to the master without deleting his code?

I apologize if its a simple question but Im kind of new to this world :)

Ryan
  • 3
  • 1

2 Answers2

1

You have to rebase your branch on master. If you have worked on same files or same lines of code than him, you will probably have to manage some conflicts during this rebase.

I suggest you to train on Git using this website : https://learngitbranching.js.org It's a great tool because it cuts the problem into small parts :

  • first you will discover the tree of (immutable) commits, and orphan commits
  • what is a branch (it is only a flag on a commit), what is the head (a flag also)

These 2 parts are very important to understand first !

  • then the effects of operations like merge, rebase, interactive rebase
0

The two approaches you have to choose from is to rebase or to merge.

At a high level, they involve getting the latest changes to master into your local clone. Rebasing your feature branch or merging changes from master and resolving any conflicts.

https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Example of how you can do a merge...

git checkout master

git pull

 git checkout my-feature-branch

git merge master

Resolve any conflict.

git add -A

git commit -a —no-edit

git push

Sio
  • 1,419
  • 1
  • 13
  • 23