Git Branches

Page content


some basic commands for branches. you can read Branch Basics and Branch Management for more details

create branch

you wanna develope a feature, fix a bug, test some stuff … you need a branch !

git checkout -b feature1

push upstream

if you have a central repo, push the feature upstream (so others can checkout as well)

git push --set-upstream origin feature1

show branch

you may have multiple branches, list them all. and update pager so list will not open in VIM !

git config --global pager.branch false
git branch
git branch -a

switch branch

from master to feature1 and back to master

git checkout master
git checkout feature1
git checkout master

update branch

after a while, when stuff got changed in master …

git switch feature 1
git merge master

merge branch

if your’re fine with your code, you merge your branch into master

git checkout master
git merge feature1

git delete branch

finally, delete the branch and process with on the master

git branch -d feature1

git delete branch force

finally, delete the branch and enforce it

git branch -D feature1


git remote prune origin --dry-run
git remote prune origin

git switch & restore

new commands in git v2.23

Create Branch

git switch -c new_branch

and switch back to master

git switch master

Restore File

Restore lastest version

git restore -- test.txt

or even from another branch

git checkout new_branch -- test.txt

git remote show origin

show local and remote branches with details

git remote show origin

Happy Git !

Any Comments ?

sha256: ebec2004d8d719f32b37cea1097e7934177b51ffc060b1ee7496257544e7a9b6