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
This is another list of helpful git commands:
Retrieve/Clone a repo = git clone (URL)
List remotes = git remote (-v for detail)
Commit graph = git log --all --decorate --oneline --graph
Retrieve/download from a remote = git fetch (remote name)
merge branch or tracking-branch = git merge (branch or tracking branch name)
Show status = git status
Upload to a remote = git push (remote name) (branch name)
stage an edit = git add (filename)
make a commit = git commit -m "description"
stage and commit = git commit -a -m "description"
List local branches = git branch
List remote branches = git branch -r
List both local and remote branches = git branch -a