Wednesday, 22 August 2018

List of Git commands which are mostly used by developer for managing branches

Git Commands

Clone branch from git repository
git clone gitrepourl

List all local branch of the repository
git branch

Fetch branch from repository
git fetch origin remoteBranchName:localNewName

Create branch from repository
git checkout -b newBranchName

Pull the remote changes of the branch
git pull origin remoteBranchName

Push changes to remote branch
git push origin remote branch name

Rename local branch locally
checkout branch you want to rename
git branch -m newName

Rename local branch locally when you are in different branch 
git branch -m oldname newname

Delete local branch
git branch -d nameOfBranch

Delete remote local branch
git push origin -d nameOfBranch

Delete old named remote branch and push new named local branch
git push origin :oldname newname

Replace local changes or get back locally deleted file from the remote branch
git checkout HEAD yourfile or directory path

Merge command for merging branch with current branch
git merge --no-ff branchNameYouWantToMerge

Commit staged change to branch
git commit -m "your comment"

Revert commit from the branch
git revert commitID
Use --no-commit perameter if you dont want to commit automatically after reverting

Revert merged commits
git revert -m 1 commitID