PyCharm how to delete a git branch locally and remotely
Deleting a git branch from GitHub or BitBucket can be done in two ways with PyCharm / IntelliJ:
- by terminal
- by UI
More info about managing branches with PyCharm / IntelliJ:
Delete git branch by terminal - locally and remotely
How to delete local branch in PyCharm by using the terminal:
git branch --delete <branch>
how to delete remote branch in PyCharm:
git push origin --delete <branch>
Where:
-d
--delete
Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream-to.
-D
Shortcut for --delete --force.
Finally the change can be propagated on other machines by:
git fetch --all --prune
Where:
git-fetch - Download objects and refs from another repository
--all
Fetch all remotes.
Delete git branch by GUI - locally and remotely
If you are not confident with the terminal commands you can follow the next steps:
- Open the PyCharm project where you want to delete the branch
- Update the project with latest updates (optional)
- VCS
- Git
- Pull ( You can do also fetch in order to get all branch changes)
- Delete the local branch
- Go to branches
- Change the selected branch to another one(you cannot delete a branch if you are using it)
- Select the local branch that you want to delete
- Show context menu
- Delete
- Delete the remote branch
- Go to branches
- Select the remote branch that you want to delete (again you need to have more than one branch in order to delete it)
- Show context menu
- Delete
- Finally you need to push the changes to the server
- VCS
- Git
- Push
Note: In order to propagate the changes to other machines you will need to fetch the changes by:
* VCS
* Git
* Fecth
Resources: