Best practices for encoding PowerShell files when uploading to GitHub

I’m having trouble with file encoding when working with PowerShell and GitHub. My PowerShell scripts get saved in Unicode format by default when I use the ISE editor. The problem is that GitHub expects UTF-8 encoding and can’t display my files properly.

For example, when I run simple commands like:

Write-Output "Hello World" | Out-File sample.txt

The resulting file uses Unicode encoding, which causes display issues on GitHub’s interface. I need to find an efficient way to handle this encoding problem without manually converting every single file before each commit. Has anyone found a good workflow for this situation?

I experienced a similar issue in the past. To resolve it, consider modifying your .gitattributes file by adding *.ps1 text eol=lf. This instructs Git on how to manage PowerShell files and automatically corrects the line endings. Additionally, you can set UTF-8 as the default encoding for Out-File by including $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' in your PowerShell profile. This approach significantly reduces manual intervention and allows Git to efficiently manage encoding.