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:
- tmux – A terminal multiplexer that helps manage multiple terminal sessions.
- lazygit – A terminal-based Git UI to manage your Git repositories easily.
Installation
You can install both using your system’s package manager:
sudo pacman -S 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
display-popup
: Creates a floating window inside tmux.-d "#{pane_current_path}"
: Ensures lazygit opens in the same directory as your current pane.-xC -yC -w 80% -h 80%
: Centers the popup and sets its size to 80% of the terminal.
This setup makes lazygit feel native to your terminal session.
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.