DEV Community

Cover image for Setting Up GitHub Environment Configurations in Neovim on Linux
gokayburuc.dev
gokayburuc.dev

Posted on

Setting Up GitHub Environment Configurations in Neovim on Linux

TOC

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Image description

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

Enter fullscreen mode Exit fullscreen mode

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>"
Enter fullscreen mode Exit fullscreen mode

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

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" }
  }
}

Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
raphaelproject001 profile image
Rafael Barbosa da Silva

Goodnight!
Congratulations! Too!👍