git branch my-branch
git checkout my-branch
git checkout -b my-branch
if 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
Or 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-name
git checkout -b my-branch
if 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-branch
git branch
or
git branch --list
Note: the current branch will be highlighted in green and marked with an asterisk.
git push -u origin my-branch
git branch -r
or if you want to show both local and remote branches, use instead:
git branch -a
git branch --merged
git branch -a --merged
We need to follow the next steps:
git checkout master
git pull origin master
git branch --merged
git merge my-branch
git push origin master
The 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-branch
git remote prune origin
If we want to see which branches will be prune without actually prune them run this instead
git remote prune origin --dry-run
git remote -v
If we want to remove one of them
git remote rm origin
Above 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