2

before I write some command I found on google, git console was saying

Your branch is up to date with 'origin/master'

when I type in git status.

So, after I typed in (git push -u origin 01-MyfeatureProductListing) that I found on google, when I check the status (git status), it is now saying :

Your branch is up to date with 'origin/01-MyfeatureProductListing'.

How do I bring it back to the old way? (Your branch is up to date with 'origin/master'), everytime when I type "git status"

Using Visual Studio 2017.

CodingValue
  • 145
  • 1
  • 2
  • 12

2 Answers2

5

To set the upstream branch of your current branch back to origin/master,
use the -u|--set-upstream-to option of git branch :

git branch -u origin/master

The -u flag you passed to git push instructed git to link your current branch to remote branch origin/01-MyfeatureProductListing. git branch -u allows you to override this to any remote branch you want.
You can also use --unset-upstream to stop having git compare your local branch with a remote branch.

You can view the links between local branches and remote branches in the .git/config file of your local clone ; if you open this file with any text editor (gedit, notepad, vscode ... ), you should see several sections looking like :

[branch "mybranch"]
    remote = origin
    merge = refs/heads/01-MyfeatureProductListing

The above means local branch mybranch is set up to track origin/01-MyfeatureProductListing.
The -u option simply updates this section.


[edit] obviously : the -u option to git push is completely optional, if you want to push without setting or updating the remote tracked branch, just drop the -u option ...

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • type `git branch -u origin/master` Get `Branch 'master' set up to track remote branch 'master' from 'origin'.` – Sarthak Raval Jun 15 '21 at 08:02
  • @SarthakRaval : yes, that's the expected behavior. Do you have a question regarding this message ? or is it just a remark to mention the message one should expect ? – LeGEC Jun 15 '21 at 08:16
  • how to check my `git status` and reenter `git branch -u origin/master` I get `warning: refname 'origin/master' is ambiguous. fatal: Ambiguous object name: 'origin/master'.` – Sarthak Raval Jun 15 '21 at 09:41
  • https://stackoverflow.com/questions/26046698/git-refname-origin-master-is-ambiguous – LeGEC Jun 15 '21 at 09:47
  • use google to search your error message `fatal: Ambiguous object name`, you will find posts explaining how to spot things (branches, tags, remote branches, references) that may confuse git because they have the same name – LeGEC Jun 15 '21 at 09:48
3

git status will show whether your current local branch is ahead or behind the remote tracking branch it is associated with.

(To bring the remote tracking branch up to date with a remote's – eg. origin – branch use git fetch, itself used by git pull.)

Because you pushed with the -u (aka --set-upstream) option a remote tracking branch for origin/01-MyfeatureProductListing was created.

If you want to compare your local working branch 01-MyfeatureProductListing with origin/master:

  1. git fetch to ensure you local repository has any changes made on the remote.

  2. git diff "origin/master..HEAD" to compare your remote tracking branch formasterwith the latest commit on your current branch (almost always aliased toHEAD`).

There is no direct way to get a git status like display between your current local branch and an arbitrary remote tracking branch.

Richard
  • 106,783
  • 21
  • 203
  • 265
  • _There is no direct way to get a git status like display between your current local branch and an arbitrary remote tracking branch_ But it was showing like so before ! I just need it to come back the way it was. (**Your branch is up to date with 'origin/master'**) – CodingValue Nov 11 '19 at 10:08
  • @CodingValue As noted by LeGAC you can change the remote tracking branch, but that will mean you will push to `master` which would seem not what you want. – Richard Nov 11 '19 at 11:04