work
Using Git | Profiling C++ | Asciinema | Jekyll |
general
Vacation Checklist |
Branches
Create new branch and switch to it:
git checkout -b branchname
Switch to an existing branch:
git checkout branchname
Merge changes from branch1 into branch2 (one of them can be main). Use rebase
for a clean history.
Alternatively, you can use merge
to keep the history of both branches.
git checkout branch2
git rebase branch1
If conflicts arises:
- Open each conflicted file
(<<<<<<<, =======, >>>>>>> markers)
. - Manually resolve the conflicts by editing the file.
- After resolving conflicts, mark the files as resolved:
git add conflicted_file
If necessary, keep one version of the other of one file:
git checkout --ours conflicted_file # Keep our version
git checkout --theirs conflicted_file # Keep their version
Finalizing rebase (notice commit w/o message):
git commit
git rebase --continue
git push origin branch2
The status can be:
DD
unmerged, both deletedAU
unmerged, added by usUD
unmerged, deleted by themUA
unmerged, added by themDU
unmerged, deleted by usAA
unmerged, both addedUU
unmerged, both modified
Push a branch to remote:
git push -u origin branchname
Delete a remote branch:
git push origin --delete branchname
List all remote branches:
git branch -r
: lists all remote branchesgit branch -a
: lists all branches (local and remote)git branch -vv
: lists all branches with their last commitgit branch --merged
: lists branches that have been merged into the current branchgit branch --no-merged
: lists branches that have not been merged into the current branch