Setting Up GitHub Environment Configurations in Neovim on Linux
Tags: git, github, neovim, vim
Published: 2024-06-03 22:43:30

## TOC 

- [Introduction](#introduction)
- [gitconfig](#gitconfig-configurations)
- [zshrc and bashrc Configurations](#zshrc-and-bashrc-configurations)
- [lazygit](lazygit)
- [Lazygit Setup and Configurations](#lazygit-setup-and-configurations)
- [Lazygit Usage](#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]` :

```bash
# HOME
cd

# open .gitconfig file
nvim .gitconfig
```
In the opened file, create a new configuration field like this:


```git
[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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3hl9bqliwsz744lny9ll.png)

**Extras**: 
- [zsh](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH)
- [OHMYZSH](https://ohmyz.sh/)


Depending on your system's shell, add the following two lines to its configuration file.

```bash
# 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 <your-access-token> with the `GIT_ACCESS_TOKEN` you received from Github.


```zsh
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](https://user-images.githubusercontent.com/1813121/87866391-79fcfe00-c93e-11ea-94a9-204947de1b39.gif)

## 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.

- [AstroNvim - Official Website](https://astronvim.com/)
- [Github - Lazygit.nvim](https://github.com/kdheepak/lazygit.nvim)
- [Github - Lazygit](https://github.com/jesseduffield/lazygit)


If you're using the 'Lazy' package manager in Neovim, install it with the following line of code:

```lua
-- 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](https://github.com/jesseduffield/lazygit).

You can also find the `lazygit` tutorial on the **_typecraft_dev_** channel.

{% embed https://www.youtube.com/watch?v=TLNdwvIFoCg %}