[...] A lot of people see me using these commands there in the videos and say "Hey Diego,
what is this command that you are using in Git that I run here and it doesn't work? "
so now, I released all the Git commands that I'm using, [...]
[♫]
Hey Dev! Today I will show you some commands, actually some
Alias ​​I set up, which are commands that I set up inside Git myself,
that save my life during the day while I'm developing, when I need to go back,
go forward, know what I'm doing,
so Git, that is a version control system,
uhm ... basically, the most used nowadays,
I don't think there's any other so widely used as Git is,
and also, it's kind of a basic requirement for those who are starting in programming.
So Git, I think nobody today is able to
create any kind of application without using some version control system,
unless the person keeps creating-- keeps creating like those ...
when are you handling a paper from school, like this ... "this time is the last one", "final project 2",
"final project final version" , "final project final final version", so Git, it saves lives,
uhm... our life in that regard.
But of course we already have a video on our channel talking about Git and Github,
and of course, you can already learn from those videos,
today I want to show you some of the Alias ​​I set up,
right here inside my development environment
to do some activities more automatically, that sometimes they are not described within Git,
in such a practical way, let's say it like that.
So let's go to the code,
what am I gonna do? I will start by creating a Git repository here just to get us started
to have some version control, so I'll create a folder here,
I'll call it, I don't know, "projetogit". [in English, "gitproject"]
I'll enter it, and "git init", of course, so we can initiate
our repository.
Just so we don't have,
uhm... an empty repository, what am I going to do? I'll open this project on VSCode,
alright? Let me give it a little zoom here,
I will start by creating a file here, let's suppose it's a project ...
Idk, in Javascript. So I will create an index.js here,
uhm ... we'll have here an "import express from 'express' ",
uhm... const app = express,
"app.listen", idk, any thing, I'm just adding some code here,
just so we can really have a version control being done, okay?
Uhm... I'll add
this file that I created here and I will commit it,
so, "create the app".
Simple as that. Now, I'll add a route here,
just so we can have the minimum of settings in here,
alright, and in here I will create a new commit. And that should be it.
So "cria rota principal". [in English "create main route"]
alright? And now we'll go, I have my cheat sheet here, but we'll go
command by command. Actually they Alias ​​that I---
Aliases that I use here,
that I will also teach you how to set up.
So the first Alias ​​I create, I'll leave a gist down here in the description of this video,
with all the Alias, okay? So just copy
and paste into your git config, I'll show you how to do that in a little while.
So the first one is "git ci",
This "git ci" is the same as "git commit".
Basically, it doesn't help that much , it's just an Alias so the command can be
shorter.
For the commit part, it doesn't help
that much, because commit is not a big word either, but I use it a lot. Alright?
Next item is the "git checkout", so today, we basically use the "git checkout"
to browse
through the git branches, right, so we have branches and everything, so for example if I am working
on a branch a branch inside my application, let's create a branch here, "git branch"
uhm... I'll call it ... "feature/routes"
let's suppose I was creating the routes of my application.
And then I would use "git checkout"
to get into this branch,
alright? "feature / routes", but, I set it uphere as "git co",
and then I just use it here, and I'm already inside the routes branch, okay?
Another one, linking to what I also have here,
it's "git cm",
for me to go back to the branch master in a much faster way, so it is a "git checkout master"
uhm... because I use this command a lot, so these Alias help me-- these Aliases help me,
uhm... in the productivity part, to write in a faster way.
The next one here too, in the checkout part too, in the branches creation part,
you saw there that before I ran the command "git branch",
the name of the branch I want to create,
and then I ran a git checkout to get in,
but I have an Alias ​​called "git cd", okay?
that I can run for example "feature
/login " for example if I were creating the login of our application,
what is it going to do,
it will create a branch and will already do a checkout, take a look.
So now, I'm already inside the branch feature/login, so he made two commands
kinda all in one, in a much faster way.
Let's go.
The next command we have here
is the "git st".
So everyone knows that on Git we have the "git status", and it shows
the status here,
of our, uhm... of our working tree,
right, which are the files that we are modifying. So for example,
if my index here, if I had modified it,
this here, right, I took a ";" off,
and also created a new file in our application, so, uhm...
"routes.js", let's say it like that,
and did a 'git status", it would show all this information, so, it shows
the ... the ... the ... the changes that are "staged", that will be added to the commit,
and the files that aren't tracked by the global yet.
But, I created an Alias ​​called "git st".
This "git st", note that it shows in a much more succinct way the information,
uhm... of the moment of our application, of the working tree. So it tells me the branch I'm working on,
it tells me the files that are modified with an "m" on the front,
or with a red "d" in case they are deleted,
and files that are not tracked by Google,
with a question ma-- by Google ... wow, I'm nuts.
By Git with a question mark in front,
so, this question mark indicates that the file it was never added to our timeline.
So, check it out, we have a much more succinct way, alright?
Of course this command, it has, uhh... basically it is the same as doing a "git status -sb",
Alright? You can see that the result is the same.
Uhm... let's go, in the same flow,
let me add this here, so I'll do a "git add",
"git commit", uhm...
"adiciona rotas", alright. [in English "add routes"]
Then everyone also knows that the we have a command called "git show",
that we can show information, for example, I do "git log",
I get this, the... the hash of my commit, of any that I give-- that I gave,
and I do a "git show" and I show the data.
And we can see that this "git show" it shows also in a way, let's say it like that,
dude, a lot of content sometimes and it doesn't show all the information we want.
And then, I added it, I created a new command,
called "git sf",
for it to show only which files were modified by a commit,
then I do a "git sf",
I add the hash of my commit,
I press enter,
and basically it tells me that in this commit here, "add routes",
it modified the files index.js and the-- and the routes.js file.
This here is basically "git sf", it comes from "git show files", right,
so this command is the same as "git show name only ", okay? And passing hash the file.
And that's basically because usually when I want,
uhm... to find out when a file was modified, if it was modified in the file,
I don't want to know what was modified, I want to know if that file was modified, so
I use this command.
And now we will start seeing commands a little more,
uhm... worked on, let's say that.
So far they were Alias just to lower the amount of stuff we type.
So let's go.
Uhm... Now, here, I have here,
uhm... the "git log", right, the "git log" everybody knows,
it shows the log of our tree,
uhm... of commits,
so I created an Alias called "git lg".
This "git lg" shows our commit tree in a much easier way to understand.
So there we have a version
"mini" of the commit hash, which can also be used to do a "git checkout", "git show",
so if I take this here, for example,
and I do a "git sf" and I put that there, it also works,
Alright? So, here in the "git log" I have version much more
reduced of.... of the log of... of our Git repository.
So I have when the gi- the command was done,
who made that commit,
and the commit description,
Alright? Here is just the title, remembering right, The full description is not displayed here.
If I have a commit with a lot of description, the "git log" shows itself
the whole description ends up getting quite impossible for us to see it
through the terminal, and then "git lg" it shows just the title, it's much easier
for us to see it.
Let's go,
uhm... the "git log", I won't show which one is the command but basically let me copy here ...
it is all this here: "git log",
uhm... "--pretty-format" and so on, but I'll leave it here in the description in a gist,
you will be able to copy it,
and then I'll show you where you can configure
these commands here.
So now we have one more command, which I think, dude, this command is awesome,
but for us to be able to test this command I'll need
to create a repository on Github, so let's go,
I will start by creating a new repository here,
I'll call it "youtube-git",
idk, youtube-test, I already had a "youtube-git",
I'll put it here as private,
alright?
Uhm… I will select the URL here to ... to send it in,
I'll go back to my branch master,
fine?
In the master branch here I can merge,
uhm... in that "feature/login" that we had created, just so it can have some files in there,
cool,
uhm... and now I'm going to set my URL there, so I'll do a "git",
uhm... "remote",
um ... "add origin", and I'm going put our "youtube-test"
nice, so now the we will run this command,
perfect, and I'm going to do a "git push origin master",
and I'll pass a "-u" here right, "-u" will basically set
our origin as being the upstream, which is like,
the ... the ... the default of .. that is the remote default that we will add
to our code. Uhm... Alright.
Now that it's here on Google Chrome, I can see there our repository is already in there,
what I'm gonna do is, I will create a new file through Github,
simulating that another developer is working on the application, as if another developer
had added a commit,
and this commit will not be here on my project, so I will create a README here for example
uhm... it can be anyway, I will commit a new file,
alright? And now, do you agree with me that this README doesn't exist yet here in our repository,
and there is a command called "git incoming".
This "git incoming", basically it goes there on Github,
and returns me all commits that I don't have in my project yet,
so here it said, hey, there is a new commit made by Diego Fernandes
inside the master branch,
uhm... its name is "create README.md" and it was done 11 seconds ago.
This "git incoming" basically, it says, dude, what are all the commits there are in your upstream
that still aren't in your project,
and of course, as we have the incoming, we also have the outgoing,
what are the commits that were made in your project that are not yet
in there, so for example
if here I do a "git pull", pull our README,
make a change on the README here,
for example, uhm... "test", I'll save it here.
I add my README as a new commit,
then, "Modify", uhm... "README",
alright? And now I do a "git outgoing"
it will tell me all the commits that I have in my project,
that are not yet inside Github, within the upstream. And in case it's here
the "Modify README", alright?
So, one more really cool command I'm using here,
I'm not going to cheat because here, look, as it is in my lo-- in my cheat sheet here,
they are very long commands but I will leave it for you to copy.
And now, come in, uhh... come in three commands that help me a lot in everyday life
in development in general,
to mainly undo the things inside Git, so let's go.
The first one is "unstage". The "unstage" is the simplest.
Let's suppose you made a change here, for example, on the index.
Uhm... I changed this here to "Hello Rocketseat".
From the moment I added it,
uhm ... that I modified this file,
it is still in an area called "unstaged",
which means, this unstaged area means this file won't go
to the next commit. If I type "git commit" here,
this file will not be on thecommit unless I do a "git add", right, a "git add.",
right now it is in the "staging area".
The staging area is all that goes to the next commit.
But what if I want to get it out of ... the staging area? Take it back to that area that doesn't go to the commit.
I can run "git unstage",
and I run "index.js" which is the filename,
if I do a git status again I see that it came back to that area that it won't go to the commit.
This is really cool because the sometimes we run a "git add ." there,
wanting to add all the commit files,
and unintentionally we added a file that shouldn't go into that commit, it should go into another,
so this helps a lot.
This is the same thing as running,
I will add the index here,
uhm ... the same as running "git reset HEAD",
alright? Uhm...
"--" and the file name, so, it's the same thing,
it already ran fine. Alright? So it's basically an Alias ​​to make this process easier.
And now, we have another one, um... another command here which is "git undo",
which is basically for undoing a change to the file.
So for example, the index, I switched here to "Hello Rocketseat",
if I want to undo this and go back to as it was at the beginning of the commit,
just "git undo index.js" it will undo and it went back to "Hello World", okay?
That would be the same-- same thing as
"git ceckout -" and the filename.
Of course, "oh, Diego, you're not saving many lines of code",
but man, it is way easier right, "git undo", "git unstage",
It's more intuitive to find out what the command does.
And now, the last, but not least,
"git rollback".
What does "git rollback" do? It will undo the last commit, but keep the files. That is the thing,
uhm... one of the things-- of the commands that I use the most, so for example,
what was our last commit we made there?
Uhm... "Modify README", then we created-- put this test here.
Let's suppose I want to go back, and undo this commit.
I just run "git rollback"
and it will undo the last commit, so "Modify README" is no longer here,
Alright? And it already left the file here in our
unstaged area, alright?
so we can
just "git commit", change this file, for example, idk, I forgot to put a ge-- a test,
Uhm... "hello" here, I wanted to put one more thing, so I do a "git add"
again, I do a "git commit", and then "Modify README",
uhm... I could simply give an "amend" of course but here it was just An example to show this in practice, easy?
Uhm... really nice, I think these here
are the main commands of Git, and how do we configure them on our...
inside our, our ... project, our machine?
Uhm... on Unix, it's basically just access-- on Unix, I mean, on Linux and on... on Mac,
on windows I don't know if there is this file, I can't say exactly,
uhm... but basically you can access a file, I'll open here on VSCode,
in the folder of your user named ".gitconfig",
if it doesn't exist, just create this file there, ok?
I will access this .gitconfig then,
here are several of my settings,
alright?
And here in the end are the Alias ​ that I'm using, which are all these,
uhm... that I showed in the video, there are more here that I don't use that much,
but, I'll leave all these Aliases ​​here available to you,
Uhm... down here in a gist, on-- in the video description, alright?
So, those were the commands, a lot of people see
me using those commands there in the videos and say "Hey Diego,
what is this command that you are using on Git, which I run here and it doesn't work? "
So now, I've released all the Git commands that I'm using,
uhm... the aliases let's say it like that, they are not commands exaclty,
but they help me a lot with development, after you gain productivity with this, you remember
to use that here,
they make it a lot easier, okay? Especially these ones here, the unstage, the undo, the rollback,
Uhm... the incoming, outgoing, lg, they all help me a lot.
So that's it, if you liked this video don't forget to leave a comment down there,
maybe some commands or Git Alias that you use yourself,
that you would like to share with the rest of the guys,
and if you liked these Aliases here that I'm using, and leave a comment saying which of these aliases
you think will save your life the most,
using Git, okay? Maybe not save the life directly but which one will be most useful
on the development of your projects.
So I'll stay around here, and, a huuge hug! Thanks!
[♫]