| title | Git branches |
|---|---|
| category | Git |
| layout | 2017/sheet |
| updated | 2020-02-13 |
{: .-three-column}
git checkout -b $branchname
git push origin $branchname --set-upstreamCreates a new branch locally then pushes it.
git fetch origin
git checkout --track origin/$branchnameGets a branch in a remote.
git remote prune originDeletes origin/* branches in your local copy. Doesn't affect the remote.
git branch --listExisting branches are listed. Current branch will be highlighted with an asterisk.
git branch -a --mergedList outdated branches that have been merged into the current one.
git branch -d $branchnameDeletes the branch only if the changes have been pushed and merged with remote.
git branch -D $branchnamegit branch -d $branchnameNote: 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.
git push origin --delete :$branchnameWorks for tags, too!
git show-ref HEAD -sgit reset --hardgit reset --hard $commit_id
# Now push safely to your branch
git push --force-with-lease
# Or push brutally to your branch
git push --force