2015-10-22 08:31:52 +01:00
|
|
|
# git branch
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2021-01-07 14:06:38 +00:00
|
|
|
> Main Git command for working with branches.
|
2019-06-03 01:06:36 +01:00
|
|
|
> More information: <https://git-scm.com/docs/git-branch>.
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2021-08-26 22:53:25 +01:00
|
|
|
- List all branches (local and remote; the current branch is highlighted by `*`):
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2021-08-26 22:53:25 +01:00
|
|
|
`git branch --all`
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2021-08-26 22:53:25 +01:00
|
|
|
- List which branches include a specific Git commit in their history:
|
2015-12-28 18:00:06 +00:00
|
|
|
|
2021-08-26 22:53:25 +01:00
|
|
|
`git branch --all --contains {{commit_hash}}`
|
2015-12-28 18:00:06 +00:00
|
|
|
|
2019-12-23 23:09:29 +00:00
|
|
|
- Show the name of the current branch:
|
|
|
|
|
|
|
|
`git branch --show-current`
|
|
|
|
|
2016-08-24 16:58:53 +01:00
|
|
|
- Create new branch based on the current commit:
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2016-08-24 16:58:53 +01:00
|
|
|
`git branch {{branch_name}}`
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2018-11-08 09:49:50 +00:00
|
|
|
- Create new branch based on a specific commit:
|
|
|
|
|
|
|
|
`git branch {{branch_name}} {{commit_hash}}`
|
|
|
|
|
2016-08-24 16:58:53 +01:00
|
|
|
- Rename a branch (must not have it checked out to do this):
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2024-08-31 12:06:48 +01:00
|
|
|
`git branch {{--move|-m}} {{old_branch_name}} {{new_branch_name}}`
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2018-12-16 10:01:47 +00:00
|
|
|
- Delete a local branch (must not have it checked out to do this):
|
2014-03-09 12:20:13 +00:00
|
|
|
|
2024-08-31 12:06:48 +01:00
|
|
|
`git branch {{--delete|-d}} {{branch_name}}`
|
2020-04-18 18:44:41 +01:00
|
|
|
|
|
|
|
- Delete a remote branch:
|
|
|
|
|
|
|
|
`git push {{remote_name}} --delete {{remote_branch_name}}`
|