Cygwin, git and ssh: ‘cannot spawn c:cygwinbinssh’

Using Cygwin and git on windows, I ran into an issue where git was working fine in a cygwin shell, but I was trying to setup a Jenkins build accessing a git repo, and git from Windows was giving errors like this:

$ git push myremote master
error: cannot spawn c:cygwinbinssh: No such file or directory
fatal: unable to fork

Running shell commands on Windows in Cygwin this was somewhat misleading, as I wasn’t expecting it to be looking for ‘ssh.exe’.

Turns out my GIT_SSH env var was causing the issue, had to replace this:

GIT_SSH=c:cygwinbinssh

with

GIT_SSH=c:cygwinbinssh.exe

and then all was good.

Removing commit history in Git

To avoid committing files to version control you can add their names to a .gitignore file, and to committing local changes to an already version controlled file you can use the git command described in my previous post here.

How can you remove history if you’ve already committed a file? For example, let’s say you have a properties file with some environment specific values that you’ve committed, but you want to remove the history of those committed values?

This FAQ walks through the steps needed, which in summary are:

    • Remove all history from the repo:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path/to/your_file_name' 
  --prune-empty --tag-name-filter cat -- --all
  • on Windows, replace the ‘ with “
  • add the filename to .gitignore if you want to avoid future commits (and commit .gitignore: git commit -m “updated gitignore” )
  • push changes back to your remotes: git push remotename master –force

If you need to make local changes to a tracked file and then not commit them in future commit, use the ‘git update-index -skip-worktree’ as described here.

Skipping locally updated files with Git

If you have a local file that you’ve updated locally (like a properties file) but you want to avoid committing the changes when you next commit, use this command:

git update-index --skip-worktree path/to/filename

If you need to add it back to the list of tracked files, then use this:

git update-index –no-skip-worktree path/to/filename

Git notes

Typical add/commit/push workflow:

#add local change ready to commit
git add .

#git commit changes to repo
git commit -m "commit message"

#push to remote repo
git push [optional remote repo name here, eg origin, etc]

Find changes committed locally compared with remote repo, i.e. to find what you’ve committed locally but not yet pushed:

git diff --stat [remote repo name]

List associated remote repos and their locations:

git remote -v

Add a new remote repo to an existing local app/repo:

git remote add remotename remote_git_repo_url