Let's Git It
Tags: git, codenewbie, beginners
Published: 2021-01-29 17:08:26

At one point a codenewbie, I found myself thoroughly confused by git commands, how to use them, when to use them, and so on. While there's many online resources outlining the commands, most of what I found wasn't 'beginner-friendly' or robust enough for my liking. In short, the documentation confused me even more. It seemed to me as if the people who wrote the docs were simply trying to help *themselves* remember the commands, as opposed to teaching a newbie what the commands meant. 

For any code beginner stumbling across my blog, this post is for you! This is git, simplified. 

####Git Clone
*git clone* is used to target an existing Git repository and make a clone of that to exist on your local machine. You are able to sync the local clone to the remote with a few commands (which I will go over later in the post). After cloning it, you can *cd* into the directory to begin coding. 

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

####Git Checkout
Speaking of new branches, *git checkout* is used to create a new branch. The command for that is *git checkout -b "your-branch-name-here"*

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

####Git Branch
*git branch* is a command used to check which branch you are currently working out of. A use case for this is when you're working on multiple features with other collaborators, you don't necessarily want to be working off the same branch. To keep things from getting mixed up or from breaking, you want to checkout a new branch to code your portion of the project. In this case, it's good practice to check what branch you're in just in case before pushing any changes. 

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

####Git Add
*git add* isn't quite the same as a traditional 'save' command. *git add* sends all the changes made to the staging area, which then is able to be saved with a different command. There are different types of *add* commands that stage certain pieces of information: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/61mvi38cab80ldle2x6b.png)

####Git Commit
*git commit* is the command used to save your local copy of the project. The most commonly used command is *git commit -m "your-message-here"* where you include a message of any changes your made. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qsoamadkoql1jzkro8kg.png)

####Git Push
*git push* is the command used to upload the local saved changes to the remote repository. After you push, it allows other collaborators to pull your branch, merge your changes with theirs, and work with the modifications you made. 

####Git Pull 
*git pull* fetches any commits from the remote branch and allows you to merge it with your branch. When you're collaborating with others, the command you'll be using frequently will be *git pull origin "name-of-branch-you-are-wanting-to-pull-from* 

In this example, my project partner's branch is called 'testbranch.' I want to merge what they have with my portion of the project in my own working branch, so I call testbranch at the end of the pull command. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cnmma3ikdb6axzr7kwhw.png)

This pull command only merges the work on your local copy. To share the merged work with the rest of your team, you will then add, commit, and push this newly merged branch for others to pull from. 

These are just the basics git commands; while there's many more that you can utilize, having a good understanding of the basics will help any beginner get a jump start into collaboration. Happy coding! 

References: 
-https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add?rq=1
-https://www.atlassian.com/git/tutorials/saving-changes