Git Branch Commands

git branch

The git branch command is used to manage branches in a Git repository. It can be used to create, list, rename, delete, and switch branches.

git branch                //To list all branches in the repository
git branch <branch-name>  //To create a new branch
git checkout <branch-name>//To switch to a different branch
git checkout -b <branch-name> //To create and switch to a new branch at the same time
git branch -m <old-branch-name> <new-branch-name> //To rename a branch
git branch -d <branch-name>    //To delete a branch

The output of git branch will show the list of branches and indicate the currently active branch with an asterisk (*).

git diff

The git diff command is used to show the difference between two points in a Git repository. It can be used to compare changes between two branches, commits, or even two different files.

git diff <commit1>..<commit2> //to see the diff between two commits
git diff <branch1>..<branch2>  //to see the diff between two branches

git show

The git show command is used to show information about a specific Git object, such as a commit, tag, or tree. It can be used to view the details of a commit, including the changes made to the files in that commit.

git show <commit-hash>

Last updated