Git
Published: 2019-12-16 01:10:27


This blog will be a brief overview of helpful git commands to make your coding life a little simpler and more organized. First, what is Git? Git is a  distributed version control system. Git was originally developed in 2005 by Linus Torvalds, the creator of the Linux operating system kernel. Other version control systems include CVS and Subversion, or SVN. Though both CVS and SVN are not distributed. 

Git saves and allows access to previous changes in your code. This means if you have broken code that wasn't broken before you can go back to the commit where things are working. Also, Git is especially helpful when coding in groups so that you can make changes to your branch of the code, while the main branch remains unchanged. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/5ykbpfhma2n0v1mizvo9.png)

Git has been widely adopted through its criticism is that it is difficult to learn. Its commands are not the same as the commands of SVN or CVS. 

If you are anything like me you have run into a problem or 500 using git. My problems often become a hot plate of git spaghetti, and me running down the hall cradling my laptop hoping to find someone, anyone who can help me figure out what Frankenstein git monster I have made and how to put it down, for the good of humanity. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/xx7mg4jo4r5i05fatulz.jpg)

I've made a shortlist of git commands I wish I had committed to memory the first 3 or 4 times they were shown to me. 

#### $ git init
creates a new local repository for you to code in. 

#### $ git merge
is a command I recently learned I was using all along. When you use the git pull command that enacts two commands. The first is a merge where the new data is merged into the old data. The second is the commit command. A commit is made of the new merged file right away. I believe the first time I was told this I said, "hmm, well that's super thoughtful of git.."

#### $ git log
Much like git hist, git log gives the history of the current branch. 

#### $ git status
Shows the files you have changed that still need to be staged for commit. 

#### $ git remote add <url>
creates a remote repository that you can push and pull from.

#### $ git checkout
is used to switch between branches in your project. 

#### $ git diff
will show the merge conflicts of a file

#### $ git diff <sourcebranch> <target>
will show the merge conflicts before merging. 
 
#### $ git branch 
You can use to see what branches you can change to, the use git checkout or often the shortcut git co to move into the chosen branch. 

#### $ git blame
is a handy little command that shows the most recent author and revision of each line in the file. It lets us know who is to blame for the infinite loop that just crashed your machine.

#### $ git rebase 
rebasing, in general, makes for a cleaner and more linear project history 
it adds the commits of a branch to the head of the branch so that the project is more linear.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/jaqsqwn37dlmayrk7wid.png)

#### $ git rebase -i Head~4
before pushing you can squash tiny commits down into one change to create a more concise commit This command will rebase the top 4 commits from the head.

There are many more useful git commands out there, and I encourage you to read into them before you start boiling that water for more git spaghetti.