My Git bash forgets my aliases. What can I do?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If Git Bash forgets your aliases every time you close the terminal, the problem is almost never the alias syntax itself. The usual issue is that the alias was typed only for the current session or stored in a startup file that Git Bash is not actually loading.
Put aliases in a file that Bash reads on startup
Aliases only persist when they are defined in a shell startup file. A common setup is:
- '
~/.bash_profilefor login-shell startup' - '
~/.bashrcfor interactive shell setup' - '
~/.bash_aliasesfor alias definitions'
A clean arrangement is to keep aliases in ~/.bash_aliases and source that file from ~/.bashrc:
Then make sure your login profile loads .bashrc:
That chain covers the common Git Bash startup flow on Windows.
Reload and verify the configuration
After editing the files, reload them in the current terminal:
If type gs reports that gs is an alias, the current shell sees it. The next step is opening a fresh Git Bash window to confirm the startup files are being read on launch.
Git aliases versus shell aliases
If the shortcut is meant only for Git, consider using Git’s built-in alias system instead of a Bash alias:
Then use:
Git aliases are often more portable because they work even in terminals that are not Bash.
Common Windows-specific issues
Git Bash on Windows introduces a few extra problems:
- profile files may exist in the wrong home directory
- editors may save startup files with Windows line endings
- different shortcuts may launch Bash with slightly different startup behavior
Check the home directory Bash is actually using:
And check file format if parsing looks broken:
If the files contain problematic line endings or syntax errors, Bash may stop reading them early and your aliases never get defined.
Debugging startup behavior
When the issue is not obvious, trace shell startup:
This prints which files were sourced and helps you catch:
- missing
sourcelines - syntax errors
- aliases overridden later by another file
That is usually faster than guessing which configuration file is responsible.
Common Pitfalls
One common mistake is defining the alias manually in the terminal and assuming it will still exist tomorrow. Session-only aliases disappear as soon as that shell exits.
Another issue is putting everything into .bash_profile and forgetting that .bashrc may be the better place for interactive shell setup. Sourcing .bashrc from .bash_profile avoids that split-brain setup.
People also edit the wrong file because they assume their Windows user directory and Bash home directory are identical. Always check $HOME.
Finally, keep shell aliases and Git aliases conceptually separate. If the shortcut is only for Git subcommands, Git’s own alias system may be the cleaner answer.
Summary
- Persistent aliases must live in a shell startup file, not only in the current session.
- A reliable Git Bash setup is
.bash_profilesourcing.bashrc, and.bashrcsourcing.bash_aliases. - Use
source,type, and startup tracing to verify what Git Bash actually loads. - Check
$HOMEand file line endings on Windows when startup behavior seems inconsistent. - Prefer Git’s built-in aliases when the shortcut is specifically for Git commands.
Related reading
- Need to reset git branch to origin version
- New file created in Xcode 9.3, wsname.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist should it be committed?
- No property found for type... custom Spring Data repository
- No qualifying bean of type for JPA repository in Spring Boot
- My images are blurry Why isn't WPF's SnapsToDevicePixels working?
- My kafka docker container cannot connect to my zookeeper docker container
- No submodule mapping found in .gitmodule for a path that's not a submodule
- Non-Recursive Merge Sort
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.