The official Git-setup in PowerShell avaible is here
The legacy command-line terminal on Windows (cmd.exe
) is ont really capable of a customized Git experience, but if you are using PowerShell
, you are in luck. This also works
if you are running PowerShell Core
on Linux
or macOS
. A package called posh-git provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
Before youβre able to run PowerShell scripts on your machine, you need to set your local ExecutionPolicy
to RemoteSigned
(basically, anything except Undefined
and Restricted
).
- If you choose
AllSigned
instead ofRemoteSigned
, also local scripts (your own) need to be digitally signed in order to be executed. WithRemoteSigned
, only scripts having the ZoneIdentifier set to Internet (were downloaded from the web) need to be signed, others not. - If you are an
administrator
and want to set it forall users on that machine
, use-Scope LocalMachine
. - If you are a
normal user, without administrative rights
, you can use-Scope CurrentUser
to set it only for you.
To set the value of ExecutionPolicy to RemoteSigned for all users use the next command:
# Administrator
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned -Force
To set the value of ExecutionPolicy to RemoteSigned for you use the next command:
# Normal user without admin priviledges
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
If you have at least PowerShell 5 or PowerShell 4
with PackageManagement installed
, you can use the package manager to install posh-git for you.
Install-Module posh-git -Scope CurrentUser -Force
Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force # Newer beta version with PowerShell Core support
To include Git information in your prompt, the posh-git module needs to be imported.
Import-Module posh-git
To have posh-git imported every time PowerShell starts, execute the Add-PoshGitToProfile command which will add the import statement into your $profile script. This script is executed everytime you open a new PowerShell console.
Add-PoshGitToProfile -AllHosts
N.B.
: Keep in mind, that there are multiple $profile scripts. E.g. one for the console and a separate one for the ISE.
Retrieve all available Git packages
winget search --name git
<# EXAMPLE OUTPUT
Name Id Version Source
---------------------------------------------------------------------------------------------------------------------------
GitFiend 9NMNKLTSZNKC Unknown msstore
My Git 9NLVK2SL2SSP Unknown msstore
GitIssuesReportGenerator 9N6SDTJ8754N Unknown msstore
GitVine 9P3BLC2GW78W Unknown msstore
GitCup 9NBLGGH4XFHP Unknown msstore
GitIt 9NBLGGH40HV7 Unknown msstore
Dev Home GitHub Extension (Preview) 9NZCC27PR6N6 Unknown msstore
GitMind - Mind Map XPFMP3C8FNRG9P Unknown msstore
Bhagavad Gita 9WZDNCRFJCV5 Unknown msstore
GitLab CI/CD Tool 9PK8QXP7H9DR Unknown msstore
GitLooker 9PK6TGX9T87P Unknown msstore
GitLurker 9N2MN78QLVKB Unknown msstore
GitMind Mind Map XP8LG65GV4C7C8 Unknown msstore
Git Git.Git 2.43.0 winget
GitNote zhaopengme.gitnote 3.1.0 winget
Agent Git Xidicone.AgentGit 1.88 winget
WimyGit Wimysoft.WimyGit 1.0.1 winget
git-absorb tummychow.git-absorb 0.6.10 winget
TortoiseGit TortoiseGit.TortoiseGit 2.15.0.0 winget
GitFiend TobySuggate.GitFiend 0.40.6 winget
Snagit 2024 TechSmith.Snagit.2024 24.0.4.1148 winget
Snagit 2023 TechSmith.Snagit.2023 23.2.2.636 winget
Snagit 2022 TechSmith.Snagit.2022 22.1.1.21427 winget
Snagit 2021 TechSmith.Snagit.2021 21.4.5.16756 winget
Snagit 2020 TechSmith.Snagit.2020 20.1.8.16558 winget
gitui StephanDilly.gitui 0.24.3 winget
GitHubReleaseNotes StefHeyenrath.GitHubReleaseNotes 1.0.8.0 winget
Upgit pluveto.Upgit 0.2.18 winget
GitBlade PirinelLtd.GitBlade 00.00.8.9 winget
Microsoft Git Microsoft.Git 2.43.0.0.0 winget
Gitify manosim.gitify 4.5.1 winget
Logitech Unifying Software Logitech.UnifyingSoftware 2.52.33 winget
Logitech Sync Logitech.Sync 3.2.204.0 winget
Logitech Solar App Logitech.Solar 1.20.28 winget
Logitech SetPoint Logitech.SetPoint 6.90.66 winget
Logitech Presentation Logitech.Presentation 1.60.33 winget
Logitech Options Logitech.Options 10.10.58 winget
Logitech Gaming Software Logitech.LGS 9.04.28 winget
Logitech G HUB Logitech.GHUB 2023.10.3254 winget
Logitech Camera Settings Logitech.CameraSettings 2.12.8.0 winget
WSJT-X Digital Modes for Weak Signal Communications in Amateur Radio K1JT.wsjtx 2.6.1 winget
lazygit JesseDuffield.lazygit 0.40.2 winget
gitg gnome.gitg 41.0 winget
GitLab Runner Gitlab.Runner 16.7.0 winget
GitKraken CLI GitKraken.cli 1.4.0 winget
Git LFS GitHub.GitLFS 3.4.1 winget
GitHub Desktop Beta GitHub.GitHubDesktop.Beta 3.1.3-beta3 winget
GitHub Desktop GitHub.GitHubDesktop 3.3.5 winget
GitHub CLI GitHub.cli 2.42.0 winget
Git Extensions GitExtensionsTeam.GitExtensions 4.2.1 winget
GitAhead GitAhead.GitAhead 2.6.3 winget
MinGit Git.MinGit 2.41.0 winget
Fork - a fast and friendly git client Fork.Fork 1.91.2 winget
FastGithub CoolPlayLin.FastGithub 2.1.4 winget
GitKraken Axosoft.GitKraken 9.11.1 winget
GitQL amrdeveloper.gitql 0.11.0 winget
GitTools GitVersion GitTools.GitVersion 5.12.0 winget
git-cola git-cola.git-cola 4.2.1 winget
Git for Windows SDK Git.SDK 1.0.8 winget
Logitech Onboard Memory Manager (LogitechOMM) Logitech.OnboardMemoryManager 1.1.6805.0 winget
#>
Install Git
write-host "Install winget tool if you don't already have it, then type this command in command prompt or Powershell."
<#
Installs the selected package, either found by searching a configured source or directly from a manifest. By default, the query must case-insensitively match the id, name, or moniker of the package.
--id Filter results by id.
-e,--exact Find package using exact match
-s,--source Find package using the specified source.
#>
winget install --id Git.Git -exact --source winget
Start a working area |
---|
# Official documentation
git help tutorial
git help: π« Retrieve all available git commands.
git help
To open the documentation page of a git command online, type the following command:
git CommandName --help
git init : π Initialize a new repository by creating an empty Git repository or reinitialize an existing one
git init
git clone : π₯ Clone a repository into a new directory
# clone a github reporsitory
<#
#>
git clone htttps://github.com/user-name/RepositoryName.git
Work on the current change |
---|
# Open the official online Manual Page
git help everyday
git add : β Add changes to the staging area
git mv : π Move or rename a file, a directory, or a symlink
restore : βͺ Restore working tree files
rm: β Remove files from the working tree and from the index
grow, mark and tweak your common history |
---|
git branch : π List, create, or delete branches
git checkout : π Switch branches or restore working tree files
git commit : βοΈ Commit changes to the repository
git reset : βͺ Reset changes in the working tree
git tag : π·οΈ Add tags to commits
Examine the history and state |
---|
# Open the official online Manual Page
git help revisions
git bisect : π Use binary search to find the commit that introduced a bug
git diff : π View the difference between changes
git grep : π Print lines matching a pattern
git log : π View commit history
git show : π« Show information about a commit
git status : π Check status of your changes
Collaborate |
---|
# Open the official online Manual Page
git help workflows
git fetch : π Download objects and refs from another repository
git pull : π Fetch changes from a remote repository
git push : π Push changes to a remote repository
Push a local branch that is not yet referenced in .git/config file
git push --set-upstream remote BranchName
The command above will add the following entry in .git/config file
[branch "BranchName"]
remote = origin
merge = refs/heads/BranchName
πΏ Manage branches: git branch
ποΈ Create and switch to a new branch: git checkout -b
π Merge changes from one branch to another: git merge
π Reapply changes on top of another branch: git rebase
π Set up a tracking branch: git branch --set-upstream-to
π Unset the upstream configuration: git branch --unset-upstream
π Pick specific commits to apply: git cherry-pick
π Merge changes from one branch to another: git merge
π Reapply changes on top of another branch: git rebase
π¦ Temporarily save changes: git stash
π¦ Apply stashed changes and remove them: git stash pop
π¦ List all stashes: git stash list
π¦ Apply stashed changes: git stash apply
π¦ Discard a stash: git stash drop
π Manage remote repositories: git remote
β Add a remote repository: git remote add
β Remove a remote repository: git remote remove
π Fetch changes from a remote repository: git fetch
π Pull changes from a remote repository: git pull
π Push changes to a remote repository: git push
π Clone a repository with all branches: git clone --mirror
βοΈ Configure Git settings: git config
βοΈ Configure global Git settings: git config --global
Set the default global email and the name of the git user
git config --global user.email "GitUserEmail"
git config --global user.name "GitUserName"
If you see the error massage after pushing your work to GitHub, don't worry
+ git push
+ ~~~~~~~~
+ CategoryInfo : NotSpecified: (To https://gith...l_scripting.git:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
See a discussion about this essue here
If Git find a directory unsafe because the current user is not the owner, run this command if you known who owns that directory
git config --global --add safe.directory ${env:USERPROFILE}\PowerShellScriptingDM
Set the correct commiter after mistakenly commiting with the wrong one
# Edit the name and email of the global commiter on the local machine
git config --global --edit
# reset the name and email of the previous commit (not yet pushed) to the current correct global commiter
git commit --amend --reset-author
# The Vim editor command to enter the edit mode is i
# The Vim editor command to save your changes is esc then :wq
# Meaning: escape (esc) the interactive mode (i) the save the changes (w) and quit the vim editor (q).
Set the name and the email of the global commiter on a local computer
git config --global user.name "user-name"
git config --global user.name@domain
βοΈ Remove a Git configuration: git reset config
The entire Pro Git book, written by Scott Chacon and Ben Straub and published by Apress, is available here.
L'intΓ©gralitΓ© du livre Pro Git, Γ©crit par Scott Chacon et Ben Straub et publiΓ© par Apress, est disponible ici.
Install GitHub CLI (Optional)
winget install --id GitHub.cli --exact --source winget
Install GitHub Desktop (Optional)
winget install --id GitHub.GitHubDesktop --exact --source winget
Install TortoiseGit (Optional)
winget install --id TortoiseGit.TortoiseGit --exact --source winget