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

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

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:


Conflicts

git status
git add path
git checkout --ours  path   # keep our version (rebase source)
git checkout --theirs path  # keep their version (rebase target)
git add path
git rm -- path
# if the file is already gone locally:
git rm --cached -- path
git add -u
git rebase --continue   # repeat until it finishes
git push origin branch2
git commit -m "merge branch1 into branch2"
git push origin branch2


Unmerged status codes


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.