1

I'm using Git for version control and have a remote repository on Github and a local master on my machine. The file I'm changing is Toxic Comment Classification.ipynb.

I make some modification to the file. Running git status shows:

modified:   Toxic Comment Classification.ipynb

Then I run:

git branch develop

git checkout develop

Now running git status tells me I'm on the local develop branch and I have changes to the Toxic Comment Classification.ipynb file.

Now I run:

git add -u

git commit -m "checkpoint"

and I get back:

[develop ef9250e] checkpoint
1 file changed, 116 insertions(+), 99 deletions(-)

All seems good. Now I want to push this local branch (develop) to my remote master branch:

git push origin master

and I get back:

Everything up-to-date

which is not what I expected / wanted. I can successfully push to origin/develop, however.

1) What am I doing incorrectly here? I'd expect to see the changes I made on my develop branch reflected in origin/master...

Finally, I try to get around this all by checking out my local master branch and merging in my local develop branch. I then run:

git push origin master

and get back:

Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/bclayman/ToxicCommentTextClassification.git
   6de47de..ef9250e  master -> master

2) Shouldn't this approach also work? Its output makes me think nothing has been updated and looking on Github doesn't show any recent update...

Thanks!

anon_swe
  • 8,791
  • 24
  • 85
  • 145
  • I don't understand the step where you are trying to push `develop` directly to `master`. Why would you even think to do that? Note that with regard to your observations, Git will typically allow you to change branches with a dirty working directory, provided that switching to another branch would not result in conflicts with the working directory. – Tim Biegeleisen Jun 24 '18 at 03:56
  • @TimBiegeleisen Just trying to understand what's possible / get a better understanding of Git. Any thoughts on why checking out master, merging in the `develop` branch and pushing to master seems to result in no change? – anon_swe Jun 24 '18 at 03:58
  • You didn't do this. You tried to push a different branch directly to the remote `master` branch. – Tim Biegeleisen Jun 24 '18 at 03:59
  • @TimBiegeleisen I'm referring to the second question (the one where I check out my local master, merge in local develop branch, and push to the remote master at origin/master) – anon_swe Jun 24 '18 at 04:03

2 Answers2

1

To push develop to master, the syntax would be:

git push origin develop:master 

The push statistics you see in your second command (push to master after merge) reflects what has been pushed: nothing.
Nothing because you already pushed it to origin/develop.
So your second push was just a fast-forward for master: origin/master adjusted its HEAD to the one of origin/develop.

x   (HEAD, master, origin/master)
 \
  y (develop, origin/develop)

git merge develop

x   (origin/master)
 \
  y (HEAD, master, develop, origin/develop)

git push

x--y (HEAD, master, origin/master, develop, origin/develop)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Very helpful. Shouldn't I be able to push to `origin/develop` from my local `develop`, switch to my local `master` branch, merge in my local `develop` branch, and then finally push to `origin/master`? I would have thought there *would* be changes to my remote `master` in that case. Why does having pushed to `origin/develop` matter here? – anon_swe Jun 24 '18 at 04:40
  • "Shouldn't I be able to push to origin/develop from my local develop, switch to my local master branch, merge in my local develop branch, and then finally push to origin/master?" That is precisely what the diagrams show. – VonC Jun 24 '18 at 04:41
  • " I would have thought there would be changes to my remote master in that case.": there are change: before, `origin/master` referenced `x`, not it references `y`. – VonC Jun 24 '18 at 04:42
  • 1
    " Why does having pushed to `origin/develop` matters here?" because your local merge fast-forwarded master to develop, which was already pushed. Pushing master pushed no new local commits (that was not *already* pushed). – VonC Jun 24 '18 at 04:43
1

Now I want to push this local branch (develop) to my remote master branch: git push origin master and I get back: Everything up-to-date

git push is git push <remote> <refspec>. refspec is not simply what branch to push to (the destination), it's also where to push from (the source). From the git-push docs...

<refspec>...

Specify what destination ref to update with what source object. The format of a <refspec> parameter is an optional plus +, followed by the source object <src>, followed by a colon :, followed by the destination ref <dst>.

The important bit is...

Otherwise, missing :<dst> means to update the same ref as the <src>.

So git push origin master is really git push master:master. Nothing has changed on master so everything is up to date.

To push develop to the remote master its git push develop:master.

While you can do this, it is not recommend as part of a normal workflow. It will greatly confuse things to have your local repository diverge from the remote.

Schwern
  • 153,029
  • 25
  • 195
  • 336