Integrating lazygit into tmux for Git Management

Created Updated
3 min read 453 words

Integrating lazygit into tmux for Git Management

Managing Git repositories within the terminal can often be a manual and repetitive task. To streamline this workflow, you can integrate lazygit , a simple Git UI, into your tmux setup. This allows you to manage Git directly from a popup window in tmux, making it easier to stage, commit, and push changes without leaving the current working directory.

Prerequisites

Before starting, ensure you have the following tools installed:

  1. tmux – A terminal multiplexer that helps manage multiple terminal sessions.
  2. lazygit – A terminal-based Git UI to manage your Git repositories easily.

Installation

You can install both using your system’s package manager:

# For tmux
sudo apt-get install tmux lazygit
brew install tmux lazygit

Step 1: Create a Keybinding for lazygit

To integrate lazygit into your tmux workflow, you can create a popup window that displays lazygit for the current working directory. Add the following line to your .tmux.conf:

bind g display-popup -E -xC -yC -w 80% -h 80% -d "#{pane_current_path}" lazygit

This keybinding will allow you to open a tmux popup window by pressing prefix + g. The popup window will take up 80% of the width and height of your terminal, centered (-xC -yC), and it will launch lazygit within the current directory (-d "#{pane_current_path}").

How It Works

  • Popup Window: The display-popup command creates a floating window within tmux, isolating lazygit from your existing panes.
  • Current Directory: By specifying -d "#{pane_current_path}", the popup will open lazygit in the same directory as your current tmux pane. This is crucial for making sure the Git repository you are working in is always the one lazygit interacts with.
  • Size and Positioning: The popup will take up 80% of both the width and height of the terminal window, providing plenty of space for lazygit’s interface without obscuring your whole screen.

Using lazygit in tmux

Once you’ve added the keybinding, you can invoke lazygit by pressing:

prefix + g

This will bring up a centered popup window running lazygit. From here, you can:

  • Stage and unstage files
  • Commit changes
  • Switch branches
  • Push and pull from remote repositories

Once you’re done, simply close the popup using q in lazygit, or by closing the tmux popup.

Final Thoughts

Integrating lazygit into tmux with a popup window enhances your Git workflow by allowing you to manage repositories quickly without switching between different windows or panes. The ability to use lazygit within your current working directory makes this keybinding a powerful addition to your tmux setup.

Let me know if you need any further tweaks or additional features added to this integration!

Add comment below...

Please refresh the page if commenting system is not visible.
Further reading