Branches are just pointers to commits, this means that Git doesn't create (and shouldn't be created manually) a whole new set of files or folders.
The following steps are applied when it's requested to work on a separate branch.
git branch <name-branch>
git checkout <name-branch>
Info: from now on, new commits will affect only the new branch.
A new local branch, with its commits, can be push on a remote repository with the command:
git push <remote> <name-branch>
Info: in the previous command, <remote>
is origin
(if the original repository has been cloned without renaming it).
To know in which branch one is working on:
git branch
Two scenarios are distinguished.
If the branch already exists in the remote repository:
<git-server>
;git branch -m <old-branch-name> <new-branch-name> git fetch origin git branch -u origin/<new-branch-name> <new-branch-name> git remote set-head origin -a
Else if the branch only exists in the local repository:
git branch -m <old-branch-name> <new-branch-name>
The next steps are intended when the work on a secondary branch is ready to be imported in the mainly one.
<name-branch>
into master
branch, switch to this one: git checkout master
git merge <name-branch>
git push origin master
If merge conflict happens it must be manually solved.
<<<<<<< HEAD changes made in master ======= changes made in <branch-name> >>>>>>> <branch-name>
master
now).To delete the branch:
git branch -d <name-branch>
git branch -help