How to create a new GitHub repo branch with our System terminal without creating that branch locally in my system

Viewed 28

I am working on a project. I have only the main branch in my GitHub repo and in my local project. Now I want to push changes to the new GitHub repo branch temp but I do not want to create any new branch for my local project.

I want only one branch for my local project and many branches for my GitHub repo.

Is there any way to create a new GitHub repo branch from the terminal?

If I am running git branch -M temp, then after running git branch -a, I am getting output as

* temp   
remotes/origin/main

Does it mean I have only one branch in my local project and its name is changed to temp?

But if I am running git branch temp, then after running git branch -a, I am getting output as

* main
  temp
  remotes/origin/main

What is the use of -M here?

1 Answers

Using a git push <refspec>, you can push a local branch to a different remote branch:

git push origin main:test

That would update origin/test with the commits from local main.


While a git branch -M temp would rename your local branch main (currently tied to its upstream branch origin/main)

That is not what you want. You need to keep your local branch as is (main) and push to a different remote branch, as explained above.

Related