0

I have some project on GitHub, there is few branches in there.

  • master
  • alpha
  • beta

for example. Now I create new branch alpha-issue1. On alpha branch was added some commits by my colleges and I want to copy this changes to my branch. First time I think git merge alpha would be good idea, but then I read about 'better way' - git pull alpha test-issue1 (if I right). So I don't know what way to chose..

YoroDiallo
  • 345
  • 3
  • 6
  • 26
  • 2
    `git pull` is essentially just `git fetch` followed by `git merge`. So this is asking whether it's better to run `git merge`, or to run `git merge`. The questions to ask are not "pull vs merge" but rather "merge vs rebase, and if merge, precisely *what* to merge". – torek Aug 19 '16 at 10:33

3 Answers3

1

To answer your question directly: a git pull is (roughly) equivalent to git fetch ; git merge. If you want to, you can read up the exact behaviour in git help pull. So the difference between merge and pull is more about typing a few more or less commands, not about any functional difference.

Regarding the example commands you gave - no, they do not make sense.

git pull alpha test-issue1

Per your question, alpha is a branch, not a remote, so this is syntactically incorrect (the syntax is git pull <remote> ...). Also, you cannot give a "target" branch with git pull, all merges go into the currently checked-out branch.

AnoE
  • 8,048
  • 1
  • 21
  • 36
0

I am not sure if I get your question right but here are my thoughts. If you branch off alpha to a new branch where you have a few commits, the standard way is to just merge that branch back to alpha after you are done with it. It is also a good practice to merge alpha onto alpha-issue1 before merging the new branch onto alpha when working in a team (many commits from different devs on the same branch). That way you would have to resolve the possible conflicts on the working branch (alpha-issue1) instead of the main (alpha). On the other hand pull is normally used when you want to update your branch with the latest commits.

HarryS
  • 186
  • 1
  • 5
0

Assuming you are on alpha-issue1, git merge alpha will replay the changes made on the alpha branch since it diverged from alpha-issue1 on top of alpha-issue1.


Assuming you are on alpha-issue1, git pull alpha will pull the changes made on alpha branch since it diverged from alpha-issue1 and merge it on alpha-issue1. As you can see, it is essentially the same.


In fact, the better question will be git-merge vs git-rebase

Community
  • 1
  • 1
Rishit Sanmukhani
  • 2,159
  • 16
  • 26