Configure the git text editor

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

When using Git, sometimes you need to write a commit message or make other changes in a text editor. By default, Git uses the system's default text editor, which may not be the one you prefer. In this challenge, you will learn how to configure the text editor used by Git.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/SetupandConfigGroup(["`Setup and Config`"]) git/SetupandConfigGroup -.-> git/config("`Set Configurations`") subgraph Lab Skills git/config -.-> lab-12673{{"`Configure the git text editor`"}} end

Configure the git text editor

You want to configure the text editor used by Git to your preferred editor.

Tasks

For this challenge, let's use the repository from https://github.com/labex-labs/git-playground.

  1. Navigate to the cloned repository and configure the identity.
  2. Configure Git to use your preferred text editor (in this example, we will use vim).
  3. Update the contents of the hello.txt file to "Hello, Git" and stage it for commit.
  4. Commit the change.
  5. Your preferred text editor (in this example, vim) should open with the commit message. Write down your commit message "Update hello.txt" and save the file.
  6. Close the text editor. The commit will be made with the message you wrote.

This is the finished result:

commit 1f19499s5387a1549f1bb5286d3d0a2b993f87e0 (HEAD -> master)
Author: xiaoshengyunan <@users.noreply.github.com>
Date: Ā  Fri Jul 21 19:26:57 2023 +0800

Ā  Ā  Update hello.txt

Summary

By using the git config command, you can configure the text editor used by Git to your preferred editor. This can make it easier and more efficient to write commit messages and make other changes in Git.

Other Git Tutorials you may like