Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
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.
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.
- Clone the
git-playgroundrepository:
git clone https://github.com/labex-labs/git-playground
- 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"
- Configure Git to use your preferred text editor (in this example, we will use vim):
git config --global core.editor "vim"
- Make a change to a file and stage it for commit:
echo "Hello, Git" > hello.txt
git add hello.txt
- Commit the change:
git commit
- 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.
- 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.