1

Alright ! I have created a branch prac. I am doing my changes, committing them and merging them with master.

In short this is what I do usually for my workflow consisting of two branches namely - Master and prac. Whenever, I want to do something, I code in prac branch

  1. git checkout prac

  2. git add whatever, git commit -m "so n so"

  3. git checkout master

  4. git merge prac

I do not delete my branch usually to be in a frame of mind that I always have one branch for practice and master for showcase of final code.Comments are welcome to improve my mindset :D

Now, I deliberately hit git push. I noticed the following

fatal: The current branch prac has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream origin prac

Now, my questions is that if I set upstream for this prac branch to remote, then will I need to do merge ? Or how basically it's different from merging?

From what I understand, after setting upstream, I already have pushed the changes to main repo. So what will be left to merge ? Or does this pushes to some new instance/fork which has to be pushed later ?

Confusion my friends confusion!!!

HalfWebDev
  • 7,022
  • 12
  • 65
  • 103
  • 1
    See also [this answer](https://stackoverflow.com/a/37770744/1256452) to a related question, which describes what an upstream setting is, and what it does for you. – torek Oct 02 '17 at 20:35
  • Thanks @torek. Lot to read and consume. – HalfWebDev Oct 03 '17 at 08:54

2 Answers2

0

The upstream setting is a relationship between your local branch and a branch on the remote repo. It has nothing to do with merging one local branch into another (except possibly if you contrive a perverse combination of config settings); it affects how refs are updated when doing a push (in situations where no configuration or command argument specifies a different behavior), and (as torek points out in comments) can also serve as a default ref for merging.

So now git push will, by default, update the prac branch on origin if you're on the prac branch locally. But this doesn't incorporate your prac changes into master on either repo - which is what merge does.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • This isn't quite right: the upstream setting affects how `git merge` behaves when run with no arguments (provided you haven't disabled this with `git config merge.defaultToUpstream false` anyway). – torek Oct 02 '17 at 20:30
  • Huh... I didn't even know `merge` *had* default behavior for what to merge. Shows how thoroughly I've read the docs, I guess... – Mark Adelsberger Oct 02 '17 at 21:10
0

It struck me seeing a dropdown on another repo that it has branches listed. So I pushed my branch by setting upstream and it did what I thought. It simply added a new branch to my repo along with master.

So I guess this answers my query

From what I understand, after setting upstream, I already have pushed the changes to main repo. So what will be left to merge ? Or does this pushes to some new instance/fork which has to be pushed later ?

Also from this I am clear about the merge thing as well. It's comparing apples and oranges.

However, useful article pointed by torek about merge and detailed insight. Now after doing this Mark's answer makes a bit more sense. Therefore accepting that

HalfWebDev
  • 7,022
  • 12
  • 65
  • 103