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 (rewrite an existing tag)
Use these Variables
tag: the GitHub tag name (e.g.v1.2.3)btag: temporary branch name created from the tagrtag: full tag ref path (refs/tags/<tag>), used for remote deletion
Example:
tag=v1.2.3
btag="b$tag"
rtag="refs/tags/$tag"
1) Create and switch to a temporary branch from the existing tag
git fetch origin --tags
git switch -c "$btag" "$tag"
2) Make changes, commit, and push the temporary branch
git commit -am "Fixes for $tag"
git push -u origin "$btag"
3) Delete old local tag, recreate the tag locally at the new HEAD
(You’re already on $btag, so the extra git switch "$btag" is redundant.)
git tag -d "$tag"
git tag "$tag"
4) Replace the remote tag
First delete the old remote tag, then push the new one. Force-update the remote tag explicitly because tags are immutable by convention and many servers reject non-fast-forward tag updates unless forced.
git push origin ":$rtag"
git push --force origin "$rtag"
5) Update the GitHub release
- Delete the existing release for
$tag - Create a new release pointing at the updated
$tag
6) Cleanup: delete the temporary branch (remote + local)
git push origin --delete "$btag"
git 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
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
Conflicts
- Check what’s conflicted:
git status
-
Resolve each conflicted path, then stage it to mark resolved:
-
Text conflicts (
UU, etc.): open file and fix<<<<<<< ======= >>>>>>>, then:
git add path
- Keep one side (still requires
git add):
git checkout --ours path # keep our version (rebase source)
git checkout --theirs path # keep their version (rebase target)
git add path
- You want the file removed (e.g.
DU/ delete-vs-modify conflict):
git rm -- path
# if the file is already gone locally:
git rm --cached -- path
git add -u
- Finalize a rebase
git rebase --continue # repeat until it finishes
git push origin branch2
- Finalize a merge (non-rebase)
git commit -m "merge branch1 into branch2"
git push origin branch2
Unmerged status codes
DDboth deletedAUadded by usUDdeleted by themUAadded by themDUdeleted by us (often: decide keep vs delete; usegit rmto delete)AAboth addedUUboth modified
History
To remove all history from a repo:
git checkout --orphan new-main
git add -A
git commit -m 'new files'
git branch -D main
git branch -m main
git push -f origin main
git branch --set-upstream-to=origin/main main
Tokens
Can use ‘regenerate’ to copy the configuration
Configuration:
repo –> public_repo
For private images, the token must have at least read:packages.