Editing Git branch

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 6: Line 6:
 
  * [[main]]
 
  * [[main]]
  
List all branches:
+
  git branch -r
  [[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:
 
* <code>git branch new_branch</code>
 
* <code>[[git checkout]] new_branch</code>
 
* <code>git branch your-existing-branch</code>
 
or
 
* <code>[[git checkout -b]]</code>
 
 
 
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/HEAD -> origin/main
 
   origin/[[main]]
 
   origin/[[main]]
Line 47: Line 18:
 
<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}}
+
[[git checkout]] -f yourbranch
 +
git branch -M yourNewBranch
  
=== Delete branch ===
+
=== Delete branch ==
  [[git branch --delete branch_name]]
+
  git branch --delete branch_name
 
  git branch --delete --force branch_name
 
  git branch --delete --force branch_name
 
=== Get current branch name ===
 
[[git rev-parse --abbrev-ref HEAD]]
 
 
[[git branch]]
 
 
 
== Change to a branch ==
 
* <code>[[git checkout]] your-existing-branch</code>
 
 
== Activities ==
 
* [[Create git branch with current changes]]
 
  
 
== Related commands ==
 
== Related commands ==
* <code>[[git checkout]]</code>
 
 
* <code>[[git commit]]</code>
 
* <code>[[git commit]]</code>
 
* <code>[[git remote]]</code>
 
* <code>[[git remote]]</code>
 
* [[Branch]]
 
* [[Branch]]
 
* <code>[[git merge]]</code>
 
* <code>[[git merge]]</code>
* <code>[[git diff]]</code>
+
* <code>[[git checkout]]</code>
* [[git show-branch]]
 
* <code>[[git clone]]</code>
 
* [[git merge-base]]
 
  
 
== See also ==
 
== See also ==
* {{git switch}}
 
 
* {{git branch}}
 
* {{git branch}}
 +
* {{git}}
 +
  
 
[[Category:Git]]
 
[[Category:Git]]

Please note that all contributions to wikieduonline may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Wikieduonline:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Advertising: