0

I've been making changes and then renaming the master to an appropriate branch name at the end. My thinking was I'd just delete the git file. I didn't feel like I needed the master because I'm always making pull requests on Github and should differentiate them from the master branch.

My process is generally:

git branch -m master nbranchName

git commit -m "details here"

git push origin -u nbranchName

I've have two problems come up:

  1. Recent push included files from a precious push request now I have to sort them out
  2. Due to problem 1, I am hesitant to start work on a new branch especially because I'm still seeing the following with I git status
On branch nbranchName
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

My changes have been accepted and merged. So I can probably just delete the whole file and re-clone but I'm trying to figure out if I'm missing a step here, and is it okay form to change the master name like I have done.

torek
  • 448,244
  • 59
  • 642
  • 775
gopher
  • 37
  • 6
  • See https://stackoverflow.com/a/66677601/1264804. You may need to make a commit _first_. – isherwood Jan 28 '22 at 16:22
  • So after all this is done. Now what? – gopher Jan 28 '22 at 16:48
  • 1
    What worries you about the message? Is it the "your branch is ahead of origin/master by 1 commit"? – j6t Jan 28 '22 at 17:34
  • Git itself is branch-name-agnostic: it doesn't care if your branch is named `main`, `master`, `foobar`, `rumplestiltskin`, etc. The branch name is for your use only. Associated *with* your (local) branch name, though, is an *upstream* name, which you may set / change with `git branch --set-upstream-to`. This is currently set to the name `origin/master`. That's what `git status` is reporting about here. If you want to set it to some other name, use `git branch --set-upstream-to=origin/nbranchName`. Note that your local repo must have an `origin/nbranchName` for this to work. – torek Jan 29 '22 at 05:19
  • The `git push origin ` operation means: *send commits as found by to `origin` if/as needed, then ask `origin` to create or update their branch named , which will create or update my origin/ if they accept the request to create or update their *. The `-u` flag here means: *after they do accept the request and my origin/ is created or updated, do the appropriate `git branch --set-upstream-to` as well*. So it's just convenient shorthand. – torek Jan 29 '22 at 05:21
  • The main (er, usual? principle? :-) ) reason that *humans* like to use the *same* name in both repositories is to keep our own brains from getting too confused. So you might like your upstream to match like this. But Git doesn't really care, and just reports based on whatever the upstream setting is. – torek Jan 29 '22 at 05:24

1 Answers1

0

By looking at the other comments about your question, we can see that one drawback in renaming your local master branch is that it still has an upstream setting which points to origin/master.

This leads to confusion when you see the message "your branch is ahead of origin/master by 1 commit" Your renamed-branch still see its' upstream setting pointing to origin/master, so the message is just telling you the truth.

This issue will not occur if you follow a more conventional approach. At the time you were renaming master, you can simply create a new branch, with the same new name you had in mind. If you push this new branch (with the -u option as mentioned by torek) then your local branch will have an appropriate upstream setting e.g. origin/myNewName

So to answer your question "what's wrong with renaming master branch", the answer is that it is not necessary, and it causes confusion with regard to the tracking to the upstream branch.

Randy Leberknight
  • 1,363
  • 9
  • 17