TOC
- Introduction
- gitconfig
- zshrc and bashrc Configurations
- lazygit
- Lazygit Setup and Configurations
- Lazygit Usage
Introduction
For those involved in Open-Source projects, dealing with frequent commits can be tedious, especially when prompted for a username and password during push/pull requests on Git.
Neovim users can streamline their git push and pull operations by configuring it to use GIT_USERNAME
and GIT_ACCESS_TOKEN
with just a click. This article will guide you through the initial setup needed for this.
.gitconfig configurations
Firstly, let's incorporate the following helper function into our .gitconfig
file to globally recognize GIT_USERNAME
and GIT_ACCESS_TOKEN
.
In Linux, navigate to the /home/
directory using cd
to access $HOME and create or edit the .gitconfig
file. If you already have a config file, append the following helper function under [credential]
:
# HOME
cd
# open .gitconfig file
nvim .gitconfig
In the opened file, create a new configuration field like this:
[user]
email = ....@yandex.com
name = G... B....
[credential]
helper = "!f() { echo \"username=${GIT_USERNAME}\"; echo \"password=${GIT_ACCESS_TOKEN}\"; }; f"
[core]
editor = nvim
Then, paste the helper function provided below it and save the file.
When using the shell with the helper function, system-wide variables named 'GIT_USERNAME' are automatically called in the username field and 'GIT_ACCESS_TOKEN' in the access_token field.
Helper Function: A helper function is a function that assists in the computation of another function. It improves code readability by performing specific calculations and giving them descriptive names.
zshrc and bashrc configurations
Extras:
Depending on your system's shell, add the following two lines to its configuration file.
# HOME directory
cd
# if you are using zsh
nvim .zshrc
# if you are using bash
nvim .bashrc
Anywhere in your .zshrc or .bashrc file, add the following variables and replace with the GIT_ACCESS_TOKEN
you received from Github.
GIT_USERNAME="<your-username>"
GIT_ACCESS_TOKEN="<your-access-token>"
Lazygit
Lazygit is a dashboard and Git manager that simplifies all Git-related operations onto one screen. It streamlines tasks like commit, file management (add/remove), ignore, merge, branch, pull/push, and more into a user-friendly interface.
Lazygit Setup and Configurations
Astro.nvim users are encouraged to integrate it with 'lazygit' installed on their system. Follow the installation steps provided in the links below if you haven't already.
If you're using the 'Lazy' package manager in Neovim, install it with the following line of code:
-- nvim v0.8.0
return {
"kdheepak/lazygit.nvim",
cmd = {
"LazyGit",
"LazyGitConfig",
"LazyGitCurrentFile",
"LazyGitFilter",
"LazyGitFilterCurrentFile",
},
-- optional for floating window border decoration
dependencies = {
"nvim-lua/plenary.nvim",
},
-- setting the keybinding for LazyGit with 'keys' is recommended in
-- order to load the plugin when the command is run for the first time
keys = {
{ "<leader>lg", "<cmd>LazyGit<cr>", desc = "LazyGit" }
}
}
Lazygit Usage
You can learn the necessary information about usage and key combinations on the Lazygit official website Github - Lazygit.
You can also find the lazygit
tutorial on the typecraft_dev channel.
Top comments (1)
Goodnight!
Congratulations! Too!👍