--- title: Git Branch date: 2023-11-24T12:30:50+00:00 tags: git identifier: "20231124T123050" --- # Branches ## Change the commit a branch points to ``` git branch -f ``` Useful if you accidentally commit to your local `main`! [Stack Overflow](https://stackoverflow.com/questions/5471174/move-branch-pointer-to-different-commit-without-checkout/5471197#5471197) ## Rename a branch ``` git branch -m ``` or ``` git branch -m ``` [Stack Overflow](https://stackoverflow.com/questions/6591213/how-can-i-rename-a-local-git-branch) ## Upstream Branches Start tracking a remote branch ``` $ git branch --set-upstream origin/branchname ``` Stop tracking the upstream branch ``` $ git branch --unset-upstream ``` ## Verbose Info Pass a few `-v` flags to `git branch` to get more useful information! ``` $ git branch -vv develop c46fa42 [origin/develop] Add exciting new integration * new-feature a1b2c3f WIP main 0cd3fd3 [origin/main] Merge pull request #123 hotfix 9a2eff5 [origin/hotfix: ahead 3, behind 2] Fix infinite loop ```