Friday, 10 May 2019

Adding only untracked files in Git repo using Powershell

Are you a .NET developer mainly still use Windows OS and use Powershell and not Git bash for example ? The following procedure can be followed to create an aliased function for adding untracked files in a Git repository. Inside your $profile file of Powershell (in case it is missing - you can run: New-Item $Profile) notepad $Profile Now add this Powershell method:
function AddUntracked-Git() {
 &git ls-files -o --exclude-standard | select | foreach { git add $_ }
}
Save the $profile file and reload it into Powershell. Then reload your $profile file with: . $profile This is similar to the source command in *nix environments IMHO. So next time you, if you are developer using Powershell in Windows against Git repo and want to just include untracked files you can run: AddUntracked-Git This follows the Powershell convention where you have verb-nouns.
Share this article on LinkedIn.

No comments:

Post a Comment