Git newbie help needed to correct new repo

Hi,
I setup a new repo on a first-time GitHub account ok then setup my WP site as a repo via the cPanel version control plugin. After a LOT of guesswork, fumbling and Googling error messages i managed to get my site into my new GitHub repo. However, since i ended up using:
git push origin master --force
I now have 2 branches :

  1. Main - which was setup when i created my initial gitHub repo and
  2. Master which now contains all my wp files

Main branch contains the .gitigmore, license and readMe.md which was setup with the gitHub repo
whilst Master is the actual branch i want to keep. How can i get the (all important) gitignore file into Master and make master the ONLY branch since i never wanted two branches, not yet anyway!

I see there’s a way to choose which branch is the main branch so could i use this feature? Would it move merge/move the .gitignore file to master? then i can remove the main branch.

GitHub tells me that the Master branch is 1 commit ahead, 1 commit behind main - what does this mean?

Any help appreciated,
thanks

If you want exactly the .gitignore file that’s on the main branch, you can checkout just that file, and then commit it to your master branch:

git checkout main -- .gitignore
git add .gitignore
git commit

Check if it’s how you want it and commit. :slightly_smiling_face:

That wouldn’t merge anything, it just decides which branch is checked out by default in a fresh clone, and shown by default on the Github UI.

It mean master contains one commit that isn’t on main, and main has one commit that isn’t on master.

Hi airtower-luna,
many thanks for the code! after i do this i guess i can create a new .readme and license type. I would then make Master the main branch - could i then remove the unwanted ‘main’ branch added after signing up?

thanks …

Sure, you can do that. Just check the branch listing for the repository. :slightly_smiling_face:

Hi again,

This doesnt seem to work - 'main appears to be unknown?? the output is thus when i run those commands:

git status
On branch master
nothing to commit, working tree clean

git checkout main -- .gitignore
fatal: invalid reference: main

git checkout main
error: pathspec 'main' did not match any file(s) known to git

Oh, sorry, that error makes sense because you had no reason to check out the main branch locally. In that case you’ll have to include the remote name, e.g. assuming the remote for your Github repo is named origin:

git checkout origin/main -- .gitignore

Still seems unknown - i checked the git config and 'origin IS defined - so i’m not sure whats going on :

git checkout origin/main -- .gitignore
fatal: invalid reference: origin/main

I kind of fixed it now though still not sure why your code didn’t work -
I deleted the main branch and recreated the .gitignore and readme .md file - once done it picked up the Wordpress license.txt in the files listing which is better than the Apache license which i wrongly specified in the old main anyway. So it seems Ok now, One branch and clean working dir.

1 Like

Glad to read you got it to work! The only reason I can think of why that reference would be unknown is if you never did a git fetch origin.

ah, no i didn’t maybe that’s it then. Its all a learning curve at the moment and i’m making notes of any solution i can find. As a newb i think im over-thinking it; the solution was really straight forward. Even if deleting main would have sent the whole repo to hell in a handcart at this early stage and being the only dev i could now re-upload and start from fresh anyway.

Thanks for your input - its great to be part of the gitHub community.

1 Like