What if your new branch is not working fine

As i created a new branch to push my sub-Folder but it’s behaving weirdo!


And when i click on ‘compare pull request’ it looks like this.

Did you have any commits on master before you created the new branch? Initializing the repo with a README does count as a commit BTW

Can you explain what you’ve done here, how you got to this point step by step? Because git thinks there is nothing (as in nothing at all, in any way) in common between master and the code you have pushed in that branch. The files may be the same, but the history is not the same, that’s what git checks, and the code you are pushing has no history at all in common with master.

If it is a branch or a fork, it should have the entire history in common + your commit/s, but it does not

I tested out the blank repo theory, and it didn’t pan out: GH doesn’t even offer to open a PR, and in fact sets the default branch to the first branch I pushed.

@naimiii How did you create the branch? Through github, or from the command line? If you used the command line, do you remember the commands you typed?

Could it be a rebase gone bad? That’s the only way I can think of to perfectly diverge two branches down to every last commit.

Possibly could also do it by downloading the code from somewhere else (or just deleting the git folder?) then re-initialising (…making a branch, re-adding remote origin, adding some commits then pushing?)

1 Like

No i don’t have any commit’s before . I only added README file while creating the repo on GitHub.

I simply create new branch for my specific sub-folder code to push because master branch was not pushing my code. And it’s not a forked repo.

Creating the README counts. You didn’t do anything weird like creating a new repo locally and setting upstream? I’m not sure then. In this case, you’ll have to do the pro trick that most every git user does at least once, and it goes like this:

  • Make a backup copy of your repo
  • Blow it away
  • Clone it again
  • Copy your changes back over from the backup.

I used git bash to create a new branch . I used 'git checkout -b ‘branch-name’ '. Then i push the code in the respective branch.

Sounds like you did everything right, so use the trick above. Could be a github glitch. Git is a finicky beast at the best of times.

1 Like

Why could you not push to master? Did it by any chance say something like the tip of the remote is ahead of yours, then just refuse to push?

Because if you created a repo with a README, you need to pull that down before you can push more changes, else it’ll be out of sync

I already pull the README file .

when i push it to the master it behaves like this.

.For the solution, I used ‘git remote -v’ command to fix it but it did not work.

remote -v just outputs information. What is the output?

At the minute you either do not have a remote repo connected, or you’ve added the wrong one, that’s what the output of git push is telling you

I pushed the code but the folder i pushed i not open up on GitHub

git remote remove origin

To make sure git forgets what’s already configured, then

git remote add origin https://github.com/your-username/the-name-of-the-repository

What’s in that folder. It is not by any chance another git repo? Does it have a .git folder in that folder. Because github uses that icon to denote a git submodule, this is almost definitely something you do not want.