

Ali Heydari
Branching
what are branches
branching allows us to diverge from the main of the work and work on something else in isolation. consepullay you can think about the branch like a separate isolated workspace.
getting a repository
working with branches
- create a branch:
git branch bugfix
- create a branch and switch:
git switch -C bugfix
orgit checkout -b bugfix
- switch between branches:
git switch master
orgit checkout master
- rename branch:
git branch -m bugfix/signp bugfix/signup
- delete branch:
git branch -d bugfix/signup
- force delete branch:
git branch -D bugfix/signup
comparing branches
- show all commit from
bugfix
branch that is not inmaster
:git log master..bugfix
git diff master..bugfix
git diff --name-only master..bugfix
git diff --name-status master..bugfix
stashing
git stash push -m "new envs"
git stash list
git stash show stash@{1}
orgit stash show 1
git stash apply 1
git stash drop 0
git stash clear
merging
- fast-forward merge (if branches have not diverged)
- 3-way merge (if branches have diverged)
fast-forward and 3-way merges
no fast-forward merging: git merge --no-ff develop
no fast-forward for all repo: git config --global ff no
- pros:
- True reflection of history
- allow reverting a feature
- cons:
- pollutes the history
viewing merged and unmerged branches
git branch --merged
git branch --no-merged
merge conflicts
- change1, change2
- change, delete
- add1, add2
graphical merge tools
- p4merge
- kdiff
- winmerge (windows only)
- meld
- vs code
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd "code --wait $MERGED"
git config --global diff.tool vscode
git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"
aborting a merge
git merge --abort
undoing a faulty merge
git reset --hard HEAD~1
git revert HEAD
git revert -m 1 HEAD
Attachments: [session video 📺](\\192.168.100.14\Training Courses\git)
Tags:lecture