GitHub tutorial 06: Install posh-git

LiLeoWang
LiLeoWang
4 هزار بار بازدید - 5 سال پیش - Since we will use PowerShell
Since we will use PowerShell for GitHub, it is a natural path to install posh-git that is a dedicated PowerShell module for Git. There are two features worth briefly mentioning here.

The first feature is, after this module is installed, when you change directory into a Git repository, the Git status summary information is displayed in the PowerShell prompt. In this example ([master ≡ +0 ~1 -0 | +0 ~1 -0 !]), it shows that,
- the current branch is master
- the local branch is at the same commit level as remote branch
- staging area in color green has zero added file, one modified file, zero removed file
- working directory in color red has zero added file, one modified file, zero removed file
- The exclamation mark (!) in red color at the end indicates there are unstaged changes in the working tree

For more details on how to interpret the Git status information, please refer to the website shown here: https://github.com/dahlbyk/posh-git

The second feature is that you can use tab to complete common git commands, remote names, and branch names. For example, if you want to enter command "git pull origin master", you can type "git pu" then press [tab], space "or" then [tab], space "ma" then [tab]. Give it a try when you have a chance. It feels good!

Before we start the installation, make sure to run PowerShell Console, not ISE, to avoid the problems mentioned in previous tutorial.

Now we come down to actually install posh-git:

- First query if posh-git module has been installed with "get-module" command.
- Then send command "install-module" to install it for current user. Of course, you can also install for all user as you see fit.
- After installation, use "import-module" to start using this newly added module.
- If you want to automatically load posh-git module each time you open PowerShell Console application, you can do so by command "add-PoshGitToProfile".
- Afterwards, you can inspect if the profile file has been updated by viewing the change with notepad $profile.CurrentUserCurrentHost command.

That's all the steps for installation. Actually there are only two essential commands: (1) install-module; (2) import-module.

Let's take a look at the whole process in PowerShell Console.

Step 1: query if posh-git module has been installed with "get-module" command

Step 2: Send command "install-module" to install it for current user. Type "Y" to install the module from "PSGallery", and wait for the installation to finish ... It usually takes less than 1 minute to finish installation. Use "get-module" command again. You will see that "posh-git" shows up this time.

Step 3: When installation is finished, use "import-module" to load posh-git module.

Step 4: Send command "add-PoshGitToProfile" to update profile file.

Step 5: Inspect the profile file with notepad.

In summary, run PowerShell Console, not ISE. Install posh-git module with install-module, then load it with import-module commands.

That's it. We are ready to move on to actually use PowerShell for GitHub.

Thanks for watching!
5 سال پیش در تاریخ 1398/03/06 منتشر شده است.
4,060 بـار بازدید شده
... بیشتر