0

I was working on the main branch of a repository that has multiple commits. But now, I want to create a new branch to this repository where I can get all the commits and codes I have done and pushed to the main branch. How do I create a new branch to get all the commits from the main branch to the new one?

Thanks.

  • What did you try? What makes you think the new branch won't have the commits from main branch? – Gaël J Aug 17 '21 at 20:32
  • 2
    Does this answer your question? [Create a branch in Git from another branch](https://stackoverflow.com/questions/4470523/create-a-branch-in-git-from-another-branch) – Renat Aug 17 '21 at 20:33
  • @GaëlJ I am unsure how I can get all the commits from the main branch to the new branch. It would be helpful if you could give instructions on how to do this. – Sudipta Bhatta Aug 17 '21 at 20:37
  • 1
    A branch is just a pointer to a specific commit. Commits aren't moved around. All you have to do is `git branch newbranch main`. This will make `newbranch` point to where `main` currently points to. – Felix Kling Aug 17 '21 at 20:49

0 Answers0