diff --git a/snippets/rename-branch.md b/snippets/rename-branch.md new file mode 100644 index 000000000..7289b4c48 --- /dev/null +++ b/snippets/rename-branch.md @@ -0,0 +1,18 @@ +--- +title: Rename a branch +tags: branch,beginner +--- + +Renames a local branch. + +- Use `git branch -m ` to rename `` to ``. + +```sh +git branch -m +``` + +```sh +git checkout master +git branch -m patch-1 patch-2 +# Renames `patch-1` to `patch-2` +``` diff --git a/snippets/rename-remote-branch.md b/snippets/rename-remote-branch.md new file mode 100644 index 000000000..0caa72e37 --- /dev/null +++ b/snippets/rename-remote-branch.md @@ -0,0 +1,26 @@ +--- +title: Rename remote branch +tags: branch,intermediate +--- + +Renames a branch both locally and on the remote. + +- Use `git branch -m ` to rename the local `` branch to ``. +- Use `git push origin --delete ` to delete the old remote branch. +- Use `git checkout ` to switch to the renamed branch. +- Use `git push origin -u ` to set `` as the remote branch for the renamed branch. + +```sh +git branch -m +git push origin --delete +git checkout +git push origin -u +``` + +```sh +git checkout master +git branch -m patch-1 patch-2 # Renamed the local branch to `patch-2` +git push origin --delete patch-1 +git checkout patch-2 +git push origin -u patch-2 # Renames the remote branch to `patch-2` +```