git branch my-branchgit checkout my-branchgit checkout -b my-branchif you want to create a branch and reset it if there is an existing one with the same name use -B option, like this
git checkout -B my-branchOr if we want to create a new branch and use a different branch as base one write the remote name plus the name of the branch like this
git checkout -b my-branch origin/branch-namegit checkout -b my-branchif you want to create a branch and reset it if there is an existing one with the same name use -B option, like this
git checkout -b my-branch origin/other-branchgit branchor
git branch --listNote: the current branch will be highlighted in green and marked with an asterisk.
git push -u origin my-branchgit branch -ror if you want to show both local and remote branches, use instead:
git branch -agit branch --merged
git branch -a --mergedWe need to follow the next steps:
git checkout master
git pull origin master
git branch --merged
git merge my-branch
git push origin masterThe first command will delete my-branch branch locally and the next one remotely and prune it from the list
git branch -d my-branch
git branch -d -r origin/my-branchgit remote prune originIf we want to see which branches will be prune without actually prune them run this instead
git remote prune origin --dry-rungit remote -vIf we want to remove one of them
git remote rm originAbove we are deleting the origin URL from the remote list
Sync upstream
git remote add upstream (URL) this adds another remote to an existing repo
git fetch upstream
git merge upstream/master
git push origin master