DEV Community

Milan Tarami
Milan Tarami

Posted on • Updated on

GIT Commands ( Woking with git branch )

Creating a new branch

$ git checkout -b YOUR_NEW_BRANCH_NAME

View all local branch

$ git branch

View all local and remote branch

$ git branch -a

Pushing a local branch to a remote server

$ git push origin YOUR_BRANCH_NAME

Set upstream branch

upsteam allows to use "git push" command

$ git push -u origin BRANCH_NAME

Switching between branch

$ git checkout BRANCH_NAME

Merging branch

make sure you have committed all changes before merging

// first switch to destination branch, where branch needs to be merged


// and run below command to merge


Deleting a local branch without merging

// switch to any other branch

$ git branch -D BRANCH_NAME

Deleting a local branch after merging

make sure you need to be in the destination branch to delete merged branch

$ git branch -d BRANCH_NAME

Deleting a branch from a remote server

$ git push origin -d BRANCH_NAME

Pulling remote branch

$ git pull origin BRANCH_NAME

Getting changes from master branch to other branch

// switch to branch

$ git rebase master

NOTE: I will be updating this post if I became more familiar with other git commands while working on git branch

comment down if I made mistake

Top comments (0)