work
| Cernlib on MacOS | Docker and Apptainer | Using Git | Asciinema | Jekyll |
c++
| Assertions | Debugging | Profiling |
Using Git
-
Clone one branch or tag, w/o history, with submodules w/o their history (shallow)
git clone -b v1.2.3 --recurse-submodules --shallow-submodules --depth 1 [repo]
Update a tag / release
Use variables to point to the GitHub tag you want to update, the temp branch and the tag ref
For example 5.12 or v5.12:
tag=v1.2.3
btag="b$tag"
ttag="refs/tags/$tag"
-
Create and switch to a temporary branch (b) from the current tag (t)
git fetch origin --tags git switch -c "$btag" "$tag" -
Make changes, commit and push
git commit -am "Fixes for $tag" git push -u origin "$btag" -
Delete old local tag, recreate tag at HEAD
git switch "$btag" git tag -d "$tag" git tag "$tag" -
Delete old remote tag, push the new tag
git push origin :"$ttag" push origin tag "$tag" -
Update the GitHub release: delete and create new one using new tag
-
Cleanup: delete remote temp branch, local temp branch
git push origin --delete "$btag" branch -D "$btag"
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 merge/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 (the rebase source)
git checkout --theirs conflicted_file # Keep their version (the rebase target)
After choosing one version, you still need to git add the file to mark it as resolved.
git add conflicted_file
Finalizing rebase (notice commit w/o message):
git rebase --continue
git push origin branch2
The status can be:
DDunmerged, both deletedAUunmerged, added by usUDunmerged, deleted by themUAunmerged, added by themDUunmerged, deleted by usAAunmerged, both addedUUunmerged, 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