After complete your task of a branch commit and push it. Then checkout to the main(normally master branch) Suppose your branch is branch1
Then merge it
git checkout master
git merge branch1
After the merge, it's safe to delete the branch:
git branch -d branch1
Additionally, git will warn you (and refuse to delete the branch) if it thinks you didn't fully merge it yet. If you forcefully delete a branch (with
There are some reasons to keep a branch around though. For example, if it's a feature branch, you may want to be able to do bugfixes on that feature still inside that branch.
git branch -D
) which is not completely merged yet, you have to do some tricks to get the unmerged commits back though (see below).There are some reasons to keep a branch around though. For example, if it's a feature branch, you may want to be able to do bugfixes on that feature still inside that branch.
If you also want to delete the branch on a remote host, you can do:
git push origin :branch1
This will forcefully delete the branch on the remote (this will not affect already checked-out repositiories though and won't prevent anyone with push access to re-push/create it).
Note: If you want to save the branch you can create a tag before deleting it. The if you want to go back to that point you can checkout that tag.
Show the branches already merge into the current branch :
git branch --merged master
lists branches merged into mastergit branch --merged
lists branches merged into HEAD (i.e. tip of current branch)git branch --no-merged
lists branches that have not been merged
When you are doing a push/pull to another repository, you are essentially syncing your local git with the remote version. In order to sync your local branches with your remote branches you need to run
git fetch -p
. This command "prunes" non-existing remote branches from your local repo.
Comments
Post a Comment