Useful Git Commands For Beginners
Tags: github, git
Published: 2020-09-02 17:02:27

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3znipgiow81xdjoad4we.png)


I’m going to share with you a few commands I’ve found extremely useful on my way to become a good software engineer.


## git log
The git log command is going to show you the history of your repo.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a4jalm637lcxpy7avoze.png)

The goods are that you can improve this command as much as you want.
git log —-oneline will show you the same but in one line.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/50y6gxb0wxgjatliy8vh.png)

if you have a big project that you implemented branches, you can run the git log command like this.
git log —-all —-graph —-decorate —-oneline
This is going to show you all, in oneline, decorate and in a graph (like a tree).



## git checkout

git checkout could be very helpful in some situations.
1) When creating a branch and jump into it.
*Usage: git checkout -b new_branch*

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/w0je4aqv1zj25nf6ejtx.png)


2) Jumping between branches
*Usage: git checkout branch_tojump*

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ibsxiieatc6aqo28paev.png)


3) With committed files but not pushed yet, is very useful to turn back into a stable version of your project.
assume your code is broken, and you can’t find what’s going on.
With git log, you can identify the SHA of your commit and make a: git checkout <commit_SHA>, this will bring you back to that specific commit.
*Usage: git checkout <commit_SHA>*

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/t5tsdnmys2lahby03dis.png)


We have made a commit that was a huge mistake and now our code is broken, we want to turn back to the commit when our code was stable, this case is the SHA of the commit called ‘Another change ‘ = ab12b0b.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uilvitfu408uuqhomf64.png)

Now HEAD is in the ab12b0b commit. and your program is working again



## git revert

What if your changes are in your remote repo, I mean are already pushed.
In that case, you can use git revert, works similar to git checkout, it will turn you back to a stable version of your project, and then you can rebuild your project history again.
*Usage: git revert <commit_SHA>*


## amend
amend is useful to append changes to a commit you haven't push yet.
Assume you make some changes and you committed them, but you are missing something, will not look professional to push the commit, and then make another one to the changes you miss.
In that case, amend could be your friend.
*Usage: git commit --amend*


## git diff

It will show the differences you have made in a file. with the + sign is telling you what lines are being added to the file.
*Usage: git diff <filename>*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cs9k7y1tvmrd5xs91jv9.png)


## git shortlog
git shortlog is going to show you a log of your repo. but you can improve it to see much more.

*git shortlog -sn*
Will show the number of commits by person.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mnr350zbjzimu83sfkpj.png)

*git shortlog -sn — all — no-merges*
Will show the commits, the person who made it, but will not include the merges.



There’s a lot more of useful command but to not make this blog longer I’ll not include them, I hope you like and find them as useful as me.
To be a better software engineer and speed up your abilities with git, I’m going to recommend this book. 📚

https://www.amazon.com/-/es/Pro-Git-Scott-Chacon-ebook/dp/B01ISNIKES/ref%3Dsr_1_5?__mk_es_US=ÅMÅŽÕÑ&dchild=1&keywords=pro+git&qid=1599060334&sr=8-5


Thanks you for reading ✌🏻.