Git Branches

Page content

Branches

some basic commands for branches. you can read the official page 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

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 switch & restore

new commands in git v2.23

https://www.banterly.net/2021/07/31/new-in-git-switch-and-restore/

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

Happy Git !

sha256: 5c77629c81653b110a1ae51e7d127821f2951412790c5050e0a424e9a1490037