Creating a copy of branch in git

Initial setup has one branch in the local repository, as shown. The name of the branch is main.

~/repoone$ ls
dirone  filetwo  README.md

~/repoone$ git branch
* main

~/repoone$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

To create an exact copy of branch main along with its current state, use git checkout as shown.

~/repoone$ git checkout -b maincopy main
Switched to a new branch 'maincopy'

Check that the branch is created and checked out.

~/repoone$ git branch
  main
* maincopy


~/repoone$ ls
dirone  filetwo  README.md

Check the status using git status. Note that, unlike branch main, it will not have any link to the remote repository. It is a local repo that you can play with as you like.

~/repoone$ git status
On branch maincopy
nothing to commit, working tree clean