Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
Introduction to Git Aliases
Next article icon

Introduction to Git Aliases

Last Updated : 08 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Git is a tool for version control, but its commands can sometimes be long and difficult to type repeatedly. That's where Git aliases come in. Aliases allow you to create shortcuts for commonly used commands, making your workflow faster and more efficient. In this article, we'll introduce you to Git aliases, show you how to set them up, and provide examples of some useful aliases.

What are Git Aliases?

A Git alias is a shorthand for a Git command or series of commands. By creating an alias, you can replace a lengthy command with a short and memorable abbreviation. This not only saves time but also reduces the risk of errors when typing commands.

For example, instead of typing git status every time you want to check the status of your repository, you could create an alias like gs to achieve the same result.

Why Use Git Aliases?

  • Efficiency: Save time by reducing the amount of typing needed.
  • Consistency: Ensure you use the same commands consistently across different projects.
  • Customization: Tailor your Git experience to suit your specific workflow.
  • Ease of Use: Simplify complex commands into straightforward ones.

Types of Git Aliases

A Git alias can be either local or global. A local alias is defined for a particular git repository whereas a global alias can be used in any repository. If you create an alias inside a git repository without the global flag, then the alias will be local by default i.e. it can be used in the current repository only. Alias created with global flags can be used in any git repository.

Creating Git Aliases

Creating Git aliases is straightforward. You can set them up in your .gitconfig file or by using Git commands directly in the terminal.

Method 1: Using Git Config

Here aliases co, br, ci, and st were created globally for the commands checkout, branch, commit, and status respectively.

If the tag "--global" isn't used then the aliases will be local by default.

git config --global alias.<custom_command_name> <original_command Name> 

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
git config
Introduction to Git Aliases

Method 2: Editing Git Config Files Directly

You can manually edit the .gitconfig files to create aliases. Global aliases are stored in the global .gitconfig file (located in the user’s home directory on Linux), while local aliases reside in the .git/config file within the repository.

The contents of the config file are as shown below.  The file contains various information like user email, name, alias, etc. After creating aliases they will be listed under the alias header. One can insert aliases under the [alias] header manually.

Config files
Introduction to Git Aliases

Let us take an example to understand how git aliases work. Let's say we have a repository Power-Puff-Girls, having 3 branches.

git branches
Introduction to Git Aliases

So here we've used the command "git br" which works the same as "git branch" command listing the branch present in the repository. Note that we can still use the "git branch"  Aliases can also be used to create a new command from a sequence of git commands.

Example:

Here we have combined reset and HEAD commands to create a new git command. Both the commands, "git unstaged app.css" and "git reset HEAD -- app.css" are equivalent.

git config --global alias.unstage 'reset HEAD --'

Method 3: Using Aliases To Create New Git Commands

By using the git aliases command we can create custom commands that execute a series of git commands and can perform specific actions. You can add the command or any other URLs any thins by using the alias command as shown below:

Create a new branch with a customized name: 

You can use the alias name that you want to give to the command and the name of the command. 

alias  <name> ='<command name>'

Examples:

Git commits and push can be done in one command and you can create a shortcut instead of using the full command by using an alias command.

alias gcp='git commit -m "Work in progress." && git push origin HEAD'

Examples of Useful Git Aliases

Here are some examples of common Git aliases that can enhance your productivity:

1. Status Alias

Instead of typing git status, you can use:

git config --global alias.st 'status'

Now, simply type git st to check your repository status.

2. Log Alias

Viewing the commit history with git log can be made easier with an alias:

git config --global alias.lg 'log --oneline --graph --all'

This alias (git lg) shows a concise, graphical representation of the commit history.

3. Checkout Alias

Switching branches frequently? Simplify git checkout with:

git config --global alias.co 'checkout'

Now, use git co [branch-name] to switch branches quickly.

4. Commit Alias

For making commits with a short message, use:

git config --global alias.ci 'commit -m'

This allows you to commit changes with git ci "your message".

5. Add Alias

Staging files for commit can be shortened from git add to:

git config --global alias.a 'add'

Use git a [file-name] to add files to the staging area.

6. Push Alias

Pushing changes to the remote repository can be abbreviated from git push to:

git config --global alias.psh 'push'

Use git psh to push your changes.

Benefits Git Aliases

  1. Git aliases can make you a faster and more efficient developer as they can save you a lot of keystrokes in the long run. For example, git commit is a frequently used command, using git ci every time instead of git commit is going to save a few keystrokes.
  2. It makes the command look simpler and clearer.

Next Article
Introduction to Git Aliases

D

DeeptiSingh
Improve
Article Tags :
  • Web Technologies
  • Git

Similar Reads

    Git Introduction
    Git is a powerful and widely used version control system that helps developers track changes in their code, collaborate with others, and manage project history effectively. Whether you are a professional developer or just starting out, understanding Git is important for modern software development.
    5 min read
    Aliases in Git
    Pre-requisite: Git Aliases are the user-friendly names given by a user to a git command so that the user doesn't need to memorize the whole lengthy syntax of a git command. Let us go through some key terminologies !: Somewhere in the ~/.gitconfig file, you will see this symbol. This is used to allow
    5 min read
    Top 70+ Git Interview Questions and Answers - 2025
    Git is a distributed version control system (DVCS) designed to track changes in source code during software development. In 2005, Linus Torvalds, who is also the creator of the Linux kernel, developed it. Today, more than 40 million people use Git universally. If you are a developer, DevOps engineer
    15+ min read
    How to List Remote Branches in Git?
    Git is a powerful version control system that allows developers to collaborate on projects, maintain code history, and manage multiple lines of development through branching. One common task when working with Git is to list all branches in a remote repository. This article will guide you through the
    3 min read
    Bare Repositories in Git
    Repositories in Git are a snapshot of the folder in which you are working on your project. You can track the progress and changes made to the project by making commits and also revert changes if not satisfactory. Repositories can be divided into two types based on the usage on a server. These are: N
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences