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 lab, 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-12759{{"`Configure the git text editor`"}} end

Configure the git text editor

For this lab, let's use the repository from https://github.com/labex-labs/git-playground. You want to configure the text editor used by Git to your preferred editor.

  1. Clone the git-playground repository:
git clone https://github.com/labex-labs/git-playground
  1. Navigate to the cloned repository and configure the identity:
cd git-playground
git config --global user.name "your-username"
git config --global user.email "your-email"
  1. Configure Git to use your preferred text editor (in this example, we will use vim):
git config --global core.editor "vim"
  1. Make a change to a file and stage it for commit:
echo "Hello, Git" > hello.txt
git add hello.txt
  1. Commit the change:
git commit
  1. 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.
  2. 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