Git branch

List all branches within a repository

git branch 


git branch --list

List all of remote branches

git branch -a

Create a local branch

git branch {branch-name}

Example: create a branch name test-100

git branch test-100

Check for the new created branch

folaukaveinga@Folaus-MacBook-Pro-3 demo % git branch

Push new local branch to remote

git push --set-upstream origin {branch-name}

Delete local branch

Use -d for safe delete. This means that if there are changes or commits in the branch that have not been commited or pushed up to remote, delete won’t work.

git branch -d {branch-name}

Use -D to force delete the specified branch, even if it has unmerged changes.

git branch -D {branch-name}

Delete a remote branch

git push origin --delete {branch-name}


Rename a branch locally

if you want to rename the branch remotely, Use push origin to reflect the change remotely.

git branch -m {new-branch-name}

Pull a remote branch to local

When you want to pull a remote branch to your local.

git pull origin {remote-branch-name}

// and

git checkout {remote-branch-name}


Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!


Leave a Reply

Your email address will not be published.