OSDN Git Service

Regular updates
[twpd/master.git] / git-branch.md
index da3ad10..0959a9c 100644 (file)
@@ -50,18 +50,31 @@ git branch -a --merged
 
 List outdated branches that have been merged into the current one.
 
+### Delete a local branch
+
+```bash
+git branch -d $branchname
+```
+
+Deletes the branch only if the changes have been pushed and merged with remote.
+
 ### Delete branch forcefully
 
 ```bash
 git branch -D $branchname
 ```
 
-Delete a branch irrespective of its merged status.
+```bash
+git branch -d $branchname
+```
+
+> Note: You can also use the -D flag which is synonymous with --delete --force instead of -d. This will delete the branch regardless of its merge status.
+> Delete a branch irrespective of its merged status.
 
 ### Delete remote branch
 
 ```bash
-git push origin :$branchname
+git push origin --delete :$branchname
 ```
 
 Works for tags, too!
@@ -71,3 +84,17 @@ Works for tags, too!
 ```bash
 git show-ref HEAD -s
 ```
+### Reset branch and remove all changes
+
+```bash
+git reset --hard
+```
+
+### Undo commits to a specific commit
+
+```bash
+git reset --hard $commit_id
+
+# Now push to your branch
+git push --force
+```