Add rename branch snippets
This commit is contained in:
18
snippets/rename-branch.md
Normal file
18
snippets/rename-branch.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
title: Rename a branch
|
||||||
|
tags: branch,beginner
|
||||||
|
---
|
||||||
|
|
||||||
|
Renames a local branch.
|
||||||
|
|
||||||
|
- Use `git branch -m <old-name> <new-name>` to rename `<old-name>` to `<new-name>`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git branch -m <old-name> <new-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git checkout master
|
||||||
|
git branch -m patch-1 patch-2
|
||||||
|
# Renames `patch-1` to `patch-2`
|
||||||
|
```
|
||||||
26
snippets/rename-remote-branch.md
Normal file
26
snippets/rename-remote-branch.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
title: Rename remote branch
|
||||||
|
tags: branch,intermediate
|
||||||
|
---
|
||||||
|
|
||||||
|
Renames a branch both locally and on the remote.
|
||||||
|
|
||||||
|
- Use `git branch -m <old-name> <new-name>` to rename the local `<old-name>` branch to `<new-name>`.
|
||||||
|
- Use `git push origin --delete <old-name>` to delete the old remote branch.
|
||||||
|
- Use `git checkout <new-name>` to switch to the renamed branch.
|
||||||
|
- Use `git push origin -u <new-name>` to set `<new-name>` as the remote branch for the renamed branch.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git branch -m <old-name> <new-name>
|
||||||
|
git push origin --delete <old-name>
|
||||||
|
git checkout <new-name>
|
||||||
|
git push origin -u <new-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
```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`
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user