Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take latest changes from dev branch to my current branch

Tags:

git

We have below branches on which we work.

master
dev
person A
person B

We both keep working on our branches i.e. person A or person B (working on same project). When person A finish the work, he commits changes to his branche and then create a pull request to merge the changes into dev, which other person B views and approve. After approval, the changes are then saved in dev.

How B can take the latest changes which A has done, from dev to his branch person B. We are using github desktop to do all the git push/pull but happy to learn commands too. Thanks.

like image 988
S Andrew Avatar asked Aug 31 '18 01:08

S Andrew


2 Answers

It's a good practice to as soon a feasible after person A pushes the changes to dev for person B to get these changes into their branch b. This is so that person B works on latest code and their eventual merge to dev is easy.

Option 1, pull

  1. Commit all changes to branch feature_branch (git status shows clean)
  2. git checkout dev
  3. git pull - this fetches the changes onto computer b and merges these changes into the local branch b. This operation should normally be a 'fast-forward' (so no merge conflicts)
  4. git checkout feature_branch
  5. git merge dev - this merges changes from b's local dev to the feature_branch.
  6. git mergetool - resolve conflicts
  7. git commit ... - commit your merge

With this option b's both local dev and feature_branch have latest changes.

Option 2, fetch

  1. Commit all changes to branch feature_branch (git status shows clean)
  2. git fetch origin dev - this downloads latest changes to dev, but doesn't merge them to local dev
  3. git merge origin/dev - this merges changes from the downloaded version of dev to the feature_branch.

In this scenario b's local feature_branch will have the most recent changes from dev as they are on the remote repo and their local dev will not have these changes. This is OK, since b isn't working on dev, he's working on feature_branch.


I like option 2 as I don't need to checkout dev, but both options are equally correct.

like image 153
tymtam Avatar answered Oct 02 '22 17:10

tymtam


These are the steps that I do for that, though using command line interface.

  1. Checkout dev branch (git checkout dev)
  2. Get the latest of dev branch (git pull)
  3. Checkout branch B (git checkout B)
  4. Merge dev branch to branch B (git merge dev)

You can follow these steps using your github desktop.

like image 29
Mac Avatar answered Oct 02 '22 17:10

Mac