a Pointer to J
Wiki · Developer tools

Git Tips

My 2¢ while using Git: fixing a missing upstream, wiping a branch's history, renaming and archiving tags, submodules, and backing up the GPG key that signs your commits.

Started Apr 12, 2024Updated Oct 23, 2026Revision 25 sections · 4 minPage history

Looking for Confusing git terminology? It's here.

Pull

added Apr 12, 2024

If you face the error below, when you do $git pull

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details

	git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

	git branch --set-upstream develop origin/<branch>

Reset the upstream with below

$ git branch --set-upstream-to=origin/main main

from $man git-branch

	   -u <upstream>, --set-upstream-to=<upstream>
		   Set up <branchname>'s tracking information so <upstream> is
		   considered <branchname>'s upstream branch. If no <branchname> is
		   specified, then it defaults to the current branch.

Commits

added Apr 12, 2024 · edited Oct 23, 2026

Removing the Whole commit history (Remote)

Stack Overflow

This uses a new branch which doesn't have any history yet.

You don't have to remove .git directory

Below, we assume you want to remove all the history under the main branch,
but you can use any branch when 'main' appears.

$ git checkout --orphan tmp_branch
$ git add -A
$ git commit -am "Init"
$ git branch -D main			# delete the branch you want to purge history
$ git branch -m main			# rename new branch to the target branch name
$ git push -f origin main

Tags

added Apr 12, 2024 · edited Oct 23, 2026

Rename a tag (Remote)

Stack Overflow

git tag new old           # Create a new local tag named `new` from tag `old`.
git tag -d old            # Delete local tag `old`.
git push origin new :old  # Push `new` to your remote named "origin", and delete
						  #     tag `old` on origin (by pushing an empty tag
						  #     name to it).

Note that if you are renaming an annotated tag, you need to ensure that
the new tag name is referencing the underlying commit and
not the old annotated tag object that you're about to delete.

If the old tag is an annotated tag, or you aren't sure,
you can use ^{} to dereference the object until a non-tag object is found:

# create a new annotated tag "new" referencing the object
# which the old annotated tag "old" was referencing:
$ git tag -a new old^{}

Archive a branch into tag

Archive

(See: Stack Overflow 1,
Stack Overflow 2 )

Give an 'archive' tag name archive/new_name to the branch you want to archive.

$ git tag archive/new_name old_branch

Push

If you want to upload this archive to Github or Gitlab,
you can do below.

(check your $ git remote -v for the remote's name, normally it is origin)

$ git push origin archive/new_name

Remove the old branch (Local)

If you don't want to preserve the old branch, you can delete one.

$ git branch -D old_branch

Remove the old branch (Remote)

$ git push -d origin old_branch

If you need to check it again, later

If you need to check the archived branch, later

You can create temporary tmp_branch and checkout to there,
with archived archive/new_name(the name which you gave to the archive branch above) tag.

$ git checkout -b tmp_branch archive/new_name

Submodules

added Apr 12, 2024 · edited Oct 23, 2026

Re-pull the submodule after cloning the parent repository

Stack Overflow

If you freshly cloned the repo or checkout to some branch,
you won't have anything under submodule.

So, use below

$ git submodule update --init --recursive

Update the submodule

$ git submodule update --recursive --remote

Backup

added Apr 12, 2024 · edited Oct 23, 2026

Backing up the GPG key that signs your commits. (Great resource here)

Export

$ gpg --list-secret-keys --keyid-format LONG
$ gpg -o backup-YY.gpg --export-options backup --export-secret-keys jeon@ptrtoj.com

Import

$ gpg --import-options restore --import backup-YY.gpg

Now, trust imported keys.

$ gpg --edit-key jeon@ptrtoj.com
gpg > trust

Output of above command

Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)

1 = I don't know or won't say
2 = I do NOT trust
3 = I trust marginally
4 = I trust fully
5 = I trust ultimately
m = back to the main menu

Your decision?

Now, type 5 to trust the key ultimately (it's your own key; for other people's keys, 4 means 'fully').

gpg > 5

gpg > quit