Horje
How to Check Branch in Git?

In Git, branches are independent lines of development that allow you to work on features or fixes without affecting the main codebase. Checking branches is important for managing project history, coordinating collaboration, and ensuring smooth development workflows. This article will walk you through the various approaches and commands to check branches in Git.

Navigate to the Git Repository Directory

Step 1: Open your terminal or command prompt

Step 2: Use the cd command to navigate to the directory where your Git repository is located:

cd /path/to/your/repository

(These steps are common for all the approaches)

Approach 1: Checking Local Branches

Local branches are branches that exist only on your local machine. They are useful for experimenting with new features or changes before merging them into the main codebase.

Execute the following command:

git branch

Output:

Screenshot-2024-04-27-233327

Running git branch will display a list of local branches in the repository, with the current branch indicated by an asterisk (*).

Approach 2: Checking Remote Branches

Remote branches are branches hosted on remote repositories such as GitHub or GitLab. They allow collaboration among team members working on the same project.

  • Use the git branch -a command to list both local and remote branches
  • Alternatively, use git branch –remote to list only remote branches.

Execute one of the following commands:

git branch -a

Output

Screenshot-2024-04-27-233420

git branch --remote

Output

Screenshot-2024-04-27-233440

Approach 3: Visualizing Branches

Understanding the relationship between branches is important for managing project history and development flow. The git show-branch command provides a visual representation of branch relationships:

git show-branch

Output

Screenshot-2024-04-27-233513

This command displays a compact view of branch activity, showing where branches diverge and merge.

Approach 4: Checking Remote Repository Information

Checking remote repository information provides insights into the remote repository’s structure, configurations, and branches. Use the git remote show <remote_name> command to view detailed information about the remote repository.

git remote show origin

Output

Screenshot-2024-04-27-233555

The command will display a detailed overview of the remote repository, including information about branches, configurations, and more.



Reffered: https://www.geeksforgeeks.org


Git

Related
How to Add All Files in Git ? How to Add All Files in Git ?
Git Pull With (Visual Studio) VS Code Git Pull With (Visual Studio) VS Code
Customizing the Git prompt Customizing the Git prompt
How to add remote origin in git? How to add remote origin in git?
How To Amend Commit Message In Git? How To Amend Commit Message In Git?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
15