Tuesday, April 13, 2021
  • Setup menu at Appearance » Menus and assign menu to Top Bar Navigation
Advertisement
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News
No Result
View All Result
NikolaNews
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News
No Result
View All Result
NikolaNews
No Result
View All Result
Home Learn to Code

Awesome Git Aliases

March 15, 2021
in Learn to Code
How to Change the WordPress Admin Login Logo
586
SHARES
3.3k
VIEWS
Share on FacebookShare on Twitter

Git is an amazingly powerful tool. It can keep track of all the code you write, let you organize your work into different branches, help you seamlessly work with other developers, and even let you time travel and make changes.

But wouldn’t it be awesome if Git could do more? What if you could customize it with your own commands, making it do anything you can imagine?

You might also like

Detect CSS Overflow Elements

How to Mine Ethereum

VS Code node:console Fix

In this three-part series, I show you exactly how to do that. You’ll learn how to create custom Git aliases you can use to run any command you’d like. I’ll also show you many useful commands you can add to Git to make it even more useful.

This article is part of the No Bullshit Git Free Intro Course. If you’re interested in Git and you want to catch the other lessons, be sure to sign up for the free course.

How to Alias Commands

Before we go any future, just what is an alias? An alias is a shortcut for running another Git command. You can set alias just like you would any other configuration value.

For example, let’s say you often mistype git status as git stats, and you wanted git stats to run the same command. You could do that by setting the alias.stats value to status like this.

git config --global alias.stats status

Boom! Just like that, you’ve created an alias.

Just like other configuration values, you can also open up your ~/.gitconfig file and add aliases there as well. This does the same thing as the command above.

[alias]
  stats = status

Shortcuts

You likely use Git every day. Commands like git status, git add and git commit are awesome.

But ugh. All that typing. Who has time for that?

Some of the most useful aliases you can set up for Git are one-or-two-character shortcuts to common commands.

[alias]
  a = add
  b = branch
  c = commit
  cl = clone
  co = checkout
  cp = cherry-pick
  m = merge
  p = push --follow-tags
  pu = pull
  r = reset
  s = status 

These aliases can be huge time savers. Instead of typing git status, you only need to type git s. Instead of git add ., you can type git a .. It may sound trivial, but give it a try, and I promise you won’t go back to typing out the full words.

Force Push

Sometimes, you need to push changes up to a remote repository and overwrite files. You may be used to doing that with git push --force.

But what happens if somebody else has already pushed changes to the same branch? Your command will wipe out their commits. That’s no good.

Git has a safer way to push changes and overwrite your commits. Instead of using the --force flag, you can use --force-with-lease. This flag will prevent you from accidentally overwriting somebody else’s commits. The way this works is a bit magical, but you can trust that it does.

You can write a force-push alias for this:

git config --global alias.force-push "push --force-with-lease"

Now you can run git force-push, which is a bit easier to remember. Of course, in the interest of saving a few keystrokes, you can also add a short version of this alias.

git config --global alias.fp force-push

Please note, you can only alias an alias in Git 2.20+.

Shell Aliases

There’s another powerful addition to Git Aliases you can use: shell aliases. If you add a ! in front of an alias’s value, you can run any shell command. For example, you can add the following alias to print out hello every time you type in git hello.

git config --global alias.hello "!echo hello"

Dad

You know ’em, you love ’em—dad jokes. When you accidentally mistype git add as git dad, it’s only appropriate that Git responds with a dad joke.

Note: I didn’t come up with this idea. The earliest reference I could find to this idea a post on Reddit.

git config --global alias.dad '!curl https://icanhazdadjoke.com/ && echo'

Now why you accidentally type git dad, you’ll get a gem like this.

Why was the robot angry? Because someone kept pressing his buttons!

Classic.

That’s All for Now

That’s for sticking with this article to the end! Hopefully, you’ve learned how to set up your own aliases, and you found some of the ones I included useful.

In the next part of this series, we’ll be taking a much deeper dive into building custom Git commands that will speed up your workflow. Until then, have fun!

If you enjoyed this article and want to learn more about Git, be sure to check out the No Bullshit Git Free Intro Course.

Website performance monitoring
Credit: DavidWalsh By: Landon Schropp

Previous Post

Run WebSphere Liberty and Open Liberty on Microsoft Azure – IBM Developer

Next Post

Should you go all-in on ABM? Monday's daily brief

Related Posts

How to Change the WordPress Admin Login Logo
Learn to Code

Detect CSS Overflow Elements

April 8, 2021
How to Mine Ethereum
Learn to Code

How to Mine Ethereum

March 26, 2021
How to Change the WordPress Admin Login Logo
Learn to Code

VS Code node:console Fix

March 24, 2021
How to Change the WordPress Admin Login Logo
Learn to Code

Now is the Time to Get Your Business Protected from Cyberthreats

March 23, 2021
How to Change the WordPress Admin Login Logo
Learn to Code

Use Logpoints!

March 22, 2021
Next Post
Should you go all-in on ABM? Monday’s daily brief

Should you go all-in on ABM? Monday's daily brief

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Plasticity in Deep Learning: Dynamic Adaptations for AI Self-Driving Cars

Plasticity in Deep Learning: Dynamic Adaptations for AI Self-Driving Cars

January 6, 2019
Microsoft, Google Use Artificial Intelligence to Fight Hackers

Microsoft, Google Use Artificial Intelligence to Fight Hackers

January 6, 2019

Categories

  • Artificial Intelligence
  • Big Data
  • Blockchain
  • Crypto News
  • Data Science
  • Digital Marketing
  • Internet Privacy
  • Internet Security
  • Learn to Code
  • Machine Learning
  • Marketing Technology
  • Neural Networks
  • Technology Companies

Don't miss it

Criminals spread malware using website contact forms with Google URLs
Internet Security

Criminals spread malware using website contact forms with Google URLs

April 13, 2021
Trends in custom software development in 2021
Data Science

Trends in custom software development in 2021

April 13, 2021
A.I. For Raspberry Pi Pico: Uctronics TinyML Learning Kit Review
Machine Learning

A.I. For Raspberry Pi Pico: Uctronics TinyML Learning Kit Review

April 13, 2021
BERT Transformers — How Do They Work? | by James Montantes | Apr, 2021
Neural Networks

BERT Transformers — How Do They Work? | by James Montantes | Apr, 2021

April 13, 2021
Bug bounties: More hackers are spotting vulnerabilities across web, mobile and IoT
Internet Security

Critical security alert: If you haven’t patched this old VPN vulnerability, assume your network is compromised

April 13, 2021
Epoch and Map of the Energy Transition through the Consensus Validator
Data Science

Epoch and Map of the Energy Transition through the Consensus Validator

April 13, 2021
NikolaNews

NikolaNews.com is an online News Portal which aims to share news about blockchain, AI, Big Data, and Data Privacy and more!

What’s New Here?

  • Criminals spread malware using website contact forms with Google URLs April 13, 2021
  • Trends in custom software development in 2021 April 13, 2021
  • A.I. For Raspberry Pi Pico: Uctronics TinyML Learning Kit Review April 13, 2021
  • BERT Transformers — How Do They Work? | by James Montantes | Apr, 2021 April 13, 2021

Subscribe to get more!

© 2019 NikolaNews.com - Global Tech Updates

No Result
View All Result
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News

© 2019 NikolaNews.com - Global Tech Updates