Showing posts with label Github. Show all posts
Showing posts with label Github. Show all posts

Thursday, May 16, 2024

Signing Git Commits: Inappropriate ioctl for device

When I attempted to sign a Git commit, I encountered the following error:


$ git commit -S -m "important change"
error: gpg failed to sign the data:
[GNUPG:] KEY_CONSIDERED AAAABBBBCCCCDDDD00000 2
[GNUPG:] BEGIN_SIGNING H8
[GNUPG:] PINENTRY_LAUNCHED 583247 curses 1.2.1 - xterm localhost:10.0 - 1000/2001 0
gpg: signing failed: Inappropriate ioctl for device
[GNUPG:] FAILURE sign 83918950
gpg: signing failed: Inappropriate ioctl for device

fatal: failed to write commit object

After an investigation, I learned that the problem could be somethign with gpg itself. To gauge whether it is the problem with gpg, we could sign a message with gpg, e.g.,


$ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

test
gpg: signing failed: Inappropriate ioctl for device
gpg: [stdin]: clear-sign failed: Inappropriate ioctl for device

Clearly, we observe the same error message. We can conclude it is the issue with gpg. It turns out that one reason of this is that tty is not set properly. To fix this, we set tty for gpg using


export GPG_TTY=$(tty)

This can be added to shell script's profiles

Tuesday, February 1, 2022

Purging a directory or a list of files from a Git repository

Sometimes we want to remove a directory or a file at a given path completely from a Git repository's history. BFG Repo-Cleaner is a recommended tool for this. Typical examples examples given are to remove files matching a name or a pattern anywhere in the repository. Sometimes this is not what we wanted, for instance, we want to remove a Readme.md in a particular directory, or remove a doc directory from a repository that has multiple files or directories of those names instead.

Below we show an example where we remove a file or a directory at a particular path. This relies on the following option of BFG Repo-Cleaner,

-bi, --strip-blobs-with-ids <blob-ids-file>  
           strip blobs with the specified Git object ids

where it is noteworthy that the argument given to this option is a file. The file contains Git object hashes of the files we wish to purge. 

In addition, to purge a directory is to purge all the files in the directory; once all of the files are gone, the directory is gone; however, BFG Repo-Cleaner would yield an error if we pass the Git object hash of a directory to it. 

The question becomes how we figure out the Git object hashes of the files we wish to purge. For this, we can use git rev-list command, e.g.,

git rev-list --all --objects | \
      grep "src/Readme.md" | \
      cut -d' ' -f1 > file_hashes.txt

Following this,

bfg -bi file_hashes.txt 

git push --force




Wednesday, December 12, 2018

Pushing Git Repositories to Multiple Remotes

According to this post, we configure as follows,


git remote add all URL_1
git remote set-url --add --push all URL_1
git remote set-url --add --push all URL_2
...
git remote set-url --add --push all URL_N

To push to the N remotes, do,

git push all

Monday, September 4, 2017

Firewall Blocked Github: Connection refused

When I am at work, I encountered the following error while attempting to access Github,

ssh: connect to host github.com port 22: Connection refused
This could be the result that the corporate firewall blocked the SSH service (TCP port 22). In this case, we can inform the ssh client to use port 443 instead according to this Stack Overflow post. To do this, we add the following configuration for the ssh client,

cat >> ~/.ssh/config << END

Host github.com
  Hostname ssh.github.com
  Port 443

END
For me to use ssh to connect to Github, the Github official documentation turns out to be very helpful.