Difference between revisions of "Git branch"
Jump to navigation
Jump to search
(20 intermediate revisions by 5 users not shown) | |||
Line 6: | Line 6: | ||
* [[main]] | * [[main]] | ||
+ | List all branches: | ||
+ | [[git branch --list]] or [[-l]] | ||
[[git branch -a]] | [[git branch -a]] | ||
+ | [[git branch -d]] | ||
+ | [[git branch -r]] | ||
− | [[Create a new branch]]: | + | [[git branch --merged]] master |
− | + | [[git branch --merged]] | |
− | + | [[git branch --no-merged]] | |
+ | |||
+ | |||
+ | [[Create a new branch]] or change branch: | ||
+ | * <code>git branch new_branch</code> | ||
+ | * <code>[[git checkout]] new_branch</code> | ||
+ | * <code>git branch your-existing-branch</code> | ||
or | or | ||
* <code>[[git checkout -b]]</code> | * <code>[[git checkout -b]]</code> | ||
Line 18: | Line 28: | ||
[[master]] | [[master]] | ||
− | git branch --list or git branch -l | + | [[git branch --list]] or git branch -l |
* [[main]] | * [[main]] | ||
Line 25: | Line 35: | ||
[[git branch --all]] | [[git branch --all]] | ||
− | git branch -r | + | [[git branch -r]] |
origin/HEAD -> origin/main | origin/HEAD -> origin/main | ||
origin/[[main]] | origin/[[main]] | ||
Line 37: | Line 47: | ||
<code>git branch --set-upstream-to=origin/main main</code> | <code>git branch --set-upstream-to=origin/main main</code> | ||
− | === Rename branch === | + | === [[Rename branch]] === |
− | + | {{rename branch}} | |
− | |||
=== Delete branch === | === Delete branch === | ||
Line 49: | Line 58: | ||
[[git branch]] | [[git branch]] | ||
+ | |||
+ | |||
+ | == Change to a branch == | ||
+ | * <code>[[git checkout]] your-existing-branch</code> | ||
+ | |||
+ | == Activities == | ||
+ | * [[Create git branch with current changes]] | ||
== Related commands == | == Related commands == | ||
Line 59: | Line 75: | ||
* [[git show-branch]] | * [[git show-branch]] | ||
* <code>[[git clone]]</code> | * <code>[[git clone]]</code> | ||
+ | * [[git merge-base]] | ||
== See also == | == See also == | ||
+ | * {{git switch}} | ||
* {{git branch}} | * {{git branch}} | ||
− | |||
− | |||
[[Category:Git]] | [[Category:Git]] |
Revision as of 10:25, 19 January 2024
git branch
list, create, or delete branches.
git branch * main
List all branches:
git branch --list or -l git branch -a git branch -d git branch -r
git branch --merged master git branch --merged git branch --no-merged
Create a new branch or change branch:
git branch new_branch
git checkout new_branch
git branch your-existing-branch
or
git branch * mynewbranch master
git branch --list or git branch -l * main
git branch --list --remotes
git branch --all
git branch -r origin/HEAD -> origin/main origin/main origin/master
git branch --unset-upstream (no output)
git branch --set-upstream-to=origin/<branch> main
git branch --set-upstream-to=origin/main main
Contents
Rename branch
git checkout -f yourbranch git branch -M yourNewBranch
Delete branch
git branch --delete branch_name git branch --delete --force branch_name
Get current branch name
git rev-parse --abbrev-ref HEAD
git branch
Change to a branch
git checkout your-existing-branch
Activities
Related commands
git checkout
git commit
git remote
- Branch
git merge
git diff
- git show-branch
git clone
- git merge-base
See also
git switch
git branch
,git: upstream
,git branch --delete branch name
,[ --list | -a | -r | -M ]
Advertising: