๐†๐ข๐ญ ๐๐ซ๐š๐ง๐œ๐ก ๐‚๐จ๐ฆ๐ฆ๐š๐ง๐

ยท

2 min read

The ๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก command in Git is used for managing branches within a repository. It provides various functionalities to create, list, delete, and manipulate branches. Below are some common use cases for the ๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก command:

๐Ÿ‘‰ ๐‚๐ซ๐ž๐š๐ญ๐ž ๐š ๐๐ž๐ฐ ๐๐ซ๐š๐ง๐œ๐ก
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Creates a new branch with the specified name.
`๐ ๐ข๐ญ ๐œ๐ก๐ž๐œ๐ค๐จ๐ฎ๐ญ -๐› <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Creates and switches to a new branch in one command.

๐Ÿ‘‰ ๐’๐ฐ๐ข๐ญ๐œ๐ก ๐๐ซ๐š๐ง๐œ๐ก๐ž๐ฌ
`๐ ๐ข๐ญ ๐œ๐ก๐ž๐œ๐ค๐จ๐ฎ๐ญ <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Switches to the specified branch.
`๐ ๐ข๐ญ ๐ฌ๐ฐ๐ข๐ญ๐œ๐ก <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Switches to the specified branch (Git version 2.23 and later).

๐Ÿ‘‰ ๐Œ๐ž๐ซ๐ ๐ž ๐๐ซ๐š๐ง๐œ๐ก๐ž๐ฌ
`๐ ๐ข๐ญ ๐ฆ๐ž๐ซ๐ ๐ž <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Merges changes from the specified branch into the current branch.

๐Ÿ‘‰ ๐‹๐ข๐ฌ๐ญ ๐๐ซ๐š๐ง๐œ๐ก๐ž๐ฌ
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก` Lists all the branches in the repository. The current branch is highlighted with an asterisk (`*`).

๐Ÿ‘‰ ๐‚๐ซ๐ž๐š๐ญ๐ž ๐š๐ง๐ ๐’๐ฐ๐ข๐ญ๐œ๐ก ๐ญ๐จ ๐š ๐๐ž๐ฐ ๐๐ซ๐š๐ง๐œ๐ก
`๐ ๐ข๐ญ ๐œ๐ก๐ž๐œ๐ค๐จ๐ฎ๐ญ -๐› <๐ง๐ž๐ฐ_๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Creates a new branch with the specified name and switches to it in a single command. (Or, using ๐ ๐ข๐ญ ๐ฌ๐ฐ๐ข๐ญ๐œ๐ก -๐œ <๐ง๐ž๐ฐ_๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž> in Git versions 2.23 and later.)

๐Ÿ‘‰ ๐‘๐ž๐ง๐š๐ฆ๐ž ๐š ๐๐ซ๐š๐ง๐œ๐ก
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก -๐ฆ <๐ง๐ž๐ฐ_๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž> Rename the current branch.
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก -๐ฆ <๐จ๐ฅ๐_๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž> <๐ง๐ž๐ฐ_๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Rename a specific branch.

๐Ÿ‘‰ ๐ƒ๐ž๐ฅ๐ž๐ญ๐ž ๐š ๐๐ซ๐š๐ง๐œ๐ก
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก -๐ <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Deletes the specified branch. The -๐ option ensures that the branch has been fully merged before deletion. If the branch contains unmerged changes, Git will prevent deletion.

`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก -๐ƒ <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Forces deletion of the specified branch, even if it contains unmerged changes.

๐Ÿ‘‰ ๐•๐ข๐ž๐ฐ ๐‘๐ž๐ฆ๐จ๐ญ๐ž ๐๐ซ๐š๐ง๐œ๐ก๐ž๐ฌ
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก -๐ซ` Lists remote branches (branches on the remote repository).

๐Ÿ‘‰ ๐•๐ข๐ž๐ฐ ๐€๐ฅ๐ฅ ๐๐ซ๐š๐ง๐œ๐ก๐ž๐ฌ (๐‹๐จ๐œ๐š๐ฅ ๐š๐ง๐ ๐‘๐ž๐ฆ๐จ๐ญ๐ž)
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก -๐š` Lists both local and remote branches.

๐Ÿ‘‰ ๐’๐ก๐จ๐ฐ ๐‚๐ฎ๐ซ๐ซ๐ž๐ง๐ญ ๐๐ซ๐š๐ง๐œ๐ก
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก โ€” ๐ฌ๐ก๐จ๐ฐ-๐œ๐ฎ๐ซ๐ซ๐ž๐ง๐ญ` Displays the name of the currently checked-out branch.

๐Ÿ‘‰ ๐•๐ข๐ž๐ฐ ๐ญ๐ก๐ž ๐‹๐š๐ฌ๐ญ ๐‚๐จ๐ฆ๐ฆ๐ข๐ญ ๐จ๐ง ๐„๐š๐œ๐ก ๐๐ซ๐š๐ง๐œ๐ก
`๐ ๐ข๐ญ ๐›๐ซ๐š๐ง๐œ๐ก -๐ฏ` Shows the last commit on each branch along with the commit message.

Did you find this article valuable?

Support Megha Sharma's Blog by becoming a sponsor. Any amount is appreciated!

ย