Git Updates for Windows, PowerShell and WSL Ubuntu
Git released new versions of their version control software last month and documented here is my experience installing version 2.18.0 64-bit Git for Windows and version 2.18.0 built from the source on WSL Ubuntu.
After installing version 2.18.0 for Windows, I was puzzled when all of the files were showing as modified directly after cloning a repository. When files are showing as modified, this can sometimes be caused by different file line endings such as LF
or CRLF
. Since I use git across Linux, OS X and Windows, I always configure with git config core.autocrlf input
so there is no line ending conversion when files are checked out. When committing files, CRLF
will be converted to LF
. For cross-platform projects, this is the recommended setting on Unix. Line ending differences were not an issue and I suspect either file permission changes or the cache rebuild when upgrading the new Windows Git was what caused my issue. Here is what I did to fix it.
First, I used git rm –cached
to unstage the files. Then I used git reset --hard
to write both the index and working directory from git’s data.
# Unstage / remove all files from the index
git rm --cached -r .
# Discard all uncommitted changes
git reset --hard
To provide some context, below are relevant screen captures from my Git for Windows installation setup.
Adjusting your PATH environment to Use Git from the Windows Command Prompt
Choosing HTTPS transport backend to Use the OpenSSL library
Configure the line ending conversion to checkout as-is, commit UNIX-style line endings
Configure terminal emulator to use with Git Bash > Use MinTTY
Configure extra options
Here are some commands to view various configuration settings.
git config --list --show-origin
(list configuration files and settings)git config --list --local
(current repository)
git config --list --global
git config --list --system
PowerShell
Prerequisite, Git for Windows with the PATH environment set to Use Git from the Windows Command Prompt.
I recommend installing the posh-git PowerShell environment for Git. This integrates Git for Windows with PowerShell to provide tab-completion and a modified prompt to indicate what branch you are in and other useful info. For installation instructions and more, view the projects README.md
SSH
To connect to your Git repos with SSH, An OpenSSH client is installed by default with Windows 10 version 1803 (Windows 10 April 2018 Update). This makes it possibe to now use SSH commands in PowerShell or the Comand prompt without the need for third party SSH Agent plugins.
Settings | Manage Optional Features | SSH Client
To see all of the available client tools, inspect the C:\Windows\System32\OpenSSH
installation folder.
- OpenSSH
- scp.exe
- sftp.exe
- sftp-server.exe
- ssh.exe
- ssh-add.exe
- ssh-agent.exe
- sshd.exe
- sshd_config_default
- ssh-keygen.exe
- ssh-keyscan.exe
- ssh-shellhost.exe
Ubuntu
UPDATE - New and Improved command line experience with Windows Terminal and Windows Subsystem for Linux 2 (WSL2).
These steps are done from within the WSL Ubuntu terminal that is available from the Windows Store.
# get the installed version
git --version
For me, on a recently updated Ubuntu 16.04, the Git version was 2.7.4, which is from March of 2016, over two years ago. To install the latest version, we need to build Git from the source code.
Install dependencies to build from the source.
sudu apt-get update
sudo apt -y install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
Clone or download the latest stable release tag from github.com/git/git/tree/master, for example, version 2.18.0: github.com/git/git/tree/v2.18.0.
git clone https://github.com/git/git.git git-source
Compile and install git from the source. e.g.,
cd git-source
make prefix=/usr/local all
sudo make prefix=/usr/local install
Verify
git --version
# optional:
# remove the source files after installation
cd ../
rm -rf git-source
If you need to convert line endings from CRLF
to LF
for an entire project, in Cygwin, use dos2unix.
Convert line endings from CRLF
to LF
for all files recursively from the current directory.
find ./ -type f -exec dos2unix {} \;