Creating Git aliases0:00
Now, if you've been working along, you might find that it starts to get pretty tedious to constantly write things like git status, or git log, or any of the commands. It just takes up a lot of time when you do it constantly. So instead, if you'd prefer, you can create aliases, and I'll show you two different ways to do that. Imagine that we want a shortcut for git status. Here's how we do that. We can update our global config file, just like we did when we were setting our name and email address. Like this, git config, we're going to edit the global configuration file, and I'm going
and email address. Like this, git config, we're going to edit the global configuration file, and I'm going to add an alias called s, s for status, and let's direct that to the status command. That's it. So now, you can do git s instead of git status. And by the way, if you're curious where this is stored, it'll be in your home directory on the Mac, and you'll want something like git config. And yeah, you can see right down here at the bottom is where we store them. So if you want, you can always edit this file manually. For instance, maybe you want l to be git log.
Removing Git aliases0:59
So if you want, you can always edit this file manually. For instance, maybe you want l to be git log. Okay, then you can update this here, if you'd prefer. Let's try it. git l, and we get the exact same thing. And of course, if you want to remove them, it's the exact same process. Either open that file and just manually delete it, or you can do git config --global, and we are going to unset the alias of l, and that'll basically delete it from the file. So now, I can no longer do git l. All right, so that's one option, but you know what?
Shell aliases for Git1:30
So now, I can no longer do git l. All right, so that's one option, but you know what? You still have to write git space and then the shortcut. If you want to make this even shorter, well, don't forget, you can create simple command-line aliases just like you do for anything else. I'll show you. I have an aliases file that I import. If you're on a Mac, you can add your aliases to your .bashrc file, there's a .bash_profile file in your home directory, any of those would be fine. In my case, I import an aliases file, and this is where I store all of mine.
Defining alias shortcuts1:55
file in your home directory, any of those would be fine. In my case, I import an aliases file, and this is where I store all of mine. And you'll see I have a bunch of helpful things, like if I want to build up Selenium, then I can run that. I even have kind of a cool routes function specifically for Laravel. Anyways, what we are interested in is right here. For example, in this case, when I want to add a file, I can say ga, and then I type the name of the file I want to add. Or if I want to add everything in the directory, I do gaa, and then gc, I use all of the time. And that basically expands to git commit -m.
Sourcing aliases file2:25
Or if I want to add everything in the directory, I do gaa, and then gc, I use all of the time. And that basically expands to git commit -m. So for example, I could say git status with gs, git aa for add everything, and gc, some commit, if I had files to commit, and in this case, we don't. So if you are working along, maybe you could edit, like I said, your bashrc file, and here's where you can see that I import my aliases file. That can be pretty useful, to have a single point where all of your system aliases are stored. But yeah, otherwise, just do alias gs='git status', save and close. You might need to open a new tab to make sure everything is sourced, but once you do, gs
But yeah, otherwise, just do alias, gs, equals git status, save and close. You might need to open a new tab to make sure everything is sourced, but once you do, gs is now something you can run anywhere.
