Best git alias list

In this article we are going to see how to use powerful git aliases that can help you navigate through huge code baselines

Aliases in Git provide a convenient way to create shortcuts for frequently used Git commands. They allow users to define their own custom commands or abbreviations for longer and complex Git operations, making them easier to remember and execute. With aliases, users can create shortcuts for commands like committing changes, pushing to remote repositories, branching, merging, and more. These custom aliases can be defined in the Git configuration file or through the command line. By using aliases, developers can significantly enhance their productivity by reducing the amount of typing required and streamlining their Git workflow. Additionally, aliases can be shared among team members, ensuring consistent and efficient Git usage across projects. Overall, aliases in Git provide a flexible and personalized way to simplify and speed up common Git operations.

FILES

The git ls-files command is a powerful tool for searching and listing files within a Git repository. It allows developers to quickly and efficiently locate specific files or patterns of interest. By running "git ls-files" with appropriate options or arguments, developers can filter files based on different criteria, such as file extensions, directory paths, or even specific keywords within file names. This command is particularly useful when dealing with large codebases or when trying to locate specific files for modifications, inspections, or other operations. With its flexibility and speed, "git ls-files" simplifies the process of file discovery within a Git repository, enabling developers to focus on the files they need and efficiently manage their projects.

This alias uses a shell script that allows you to look for files using any part of their path name, so that you can filter them out:


f  = "!f() { cmd=\"*\"; for txt in $@; do cmd=$cmd$txt*; done; git ls-files $cmd; }; f"

Here is an example of how to use it:

git find files

TEXT

The git grep command is an indispensable tool for searching text within a Git repository. It allows developers to search not only for file names but also for specific patterns or content within the files themselves. With "git grep," developers can easily locate instances of a particular string, regular expression, or keyword across all tracked files in the repository. This command offers various options to refine the search, such as case sensitivity, specifying file types, or limiting the search to specific directories. "git grep" also provides context around the matched lines, making it easier to understand the context of the search results. By leveraging the power of "git grep," developers can swiftly navigate through the codebase, find occurrences of specific text, and gain valuable insights for debugging, refactoring, or analyzing code.

This alias uses a shell script that allows you to look for multiple strings in text files:


g  = "!f() { txt=\"--break -e $1\"; shift; for arg in $@; do txt=$txt\" --and -e $arg\"; done; git grep -i -I -n --heading $txt --all-match; }; f"

Here is an example of how to use it:

git grep text

COMMIT MESSAGE

The git log command is an essential tool for exploring and searching commit history within a Git repository. While primarily used to view the chronological order of commits, it can also be leveraged to search commit messages efficiently.

This alias allows you to look for multiple strings in commit messages:


s  = "!f() { for arg in $@; do msg=$msg\"--grep=$arg \"; done; git log $msg --all-match; }; f"

Here is an example of how to use it:

git search commit message

LOG

The git log command with the compact format is a concise and informative way to view the commit history of a Git repository. By using the --oneline option, the command displays each commit as a single line, providing essential information in a condensed format. The compact format typically shows the commit hash, the commit message summary, and the author's name, all in a visually compact representation. This format is particularly useful when you want to get a quick overview of the commit history or when working with limited screen space. The compact git log format allows developers to scan through commits efficiently, identify important changes, and track the evolution of the repository without the clutter of extensive commit details.

This alias allows you to list the log of the current branch in a compact form:


l  = log --date=short --pretty=format:'%C(yellow)%h %C(green)%ad %C(auto)%d %Creset %s'

Here is an example of how to use it:

git log

LOG ALL BRANCHES

The git log command with the graph option is a powerful tool for visualizing the commit history and branch relationships within a Git repository. By using the --graph flag, the command presents the commit graph in a structured and hierarchical manner, showing the branching and merging of different branches. This graphical representation allows developers to understand the chronological flow of commits, the order of branch creation and merging, and the relationships between different branches. The graph view provides a clear visual representation of the repository's history, making it easier to comprehend complex branching and merging patterns. It enables developers to track the evolution of code, identify merge conflicts or divergent branches, and gain insights into the overall project development.

Similar to the previous one, this alias allows you to list the log of the repository, but showing you all the branches including a graph:


ll = log --all --graph --date=short --pretty=format:'%C(yellow)%h %C(green)%ad %C(auto)%d %Creset %s'

Here is an example of its output:

git log all branches

ALIAS LIST

The following alias list includes the ones that we have already covered, together with some additional ones that are really useful for day to day tasks. You can directly include them into your .gitconfig file:
[alias]
        f  = "!f() { txt=*; for arg in $@; do txt=$txt$arg*; done; git ls-files $txt; }; f"
        g  = "!f() { txt=\"--break -e $1\"; shift; for arg in $@; do txt=$txt\" --and -e $arg\"; done; git grep -i -I -n --heading $txt --all-match; }; f"
        s  = "!f() { for arg in $@; do msg=$msg\"--grep=$arg \"; done; git log $msg --all-match; }; f"
        l  = log --date=short --pretty=format:'%C(yellow)%h %C(green)%ad %C(auto)%d %Creset %s'
        ll = log --all --graph --date=short --pretty=format:'%C(yellow)%h %C(green)%ad %C(auto)%d %Creset %s'
        o  = show --oneline --name-only
        d  = diff -w
        a  = apply --3way
        b  = branch -avv
        r  = remote -v
        t  = tag -l --sort=-creatordate
        cl = clean -f
        co = commit -a
        st = status
        rt = restore
        mt = mergetool

Popular posts from this blog

How to setup NeoVim configuration file

WebAssembly (Wasm): Fixing the Flaws of Applets

How to query Outlook from PowerShell