Git Intro for Beginners
Tags: beginners, productivity, git, programming
Published: 2020-11-17 09:45:09

**What is Git?**
Git is a free, open source distributed version control system tool designed to handle everything from small to very large projects with speed and efficiency. Git has the functionality, performance, security and flexibility that most teams, individual developers and researchers need. It was created by Linus Torvalds in 2005 to develop Linux Kernel.

**What is the purpose of Git?**
Git is primarily used to manage your project, comprising a set of code or text files that may change that may change over time.

Git is also used to save your remotely and allow access to multiple individuals for updates.

**Here are 15 git commands to master for a start**

**git init**
This command is used to initialize or start a new git repo
see sample below. Navigate into the folder you're initializing if it already exist, or simply create a new one.

![Alt git init](https://dev-to-uploads.s3.amazonaws.com/i/66z1itgenaz61t669qt3.PNG)


**git config**
The `git config` command sets the author name and email address respectively to be used with your commits.

![Alt git config](https://dev-to-uploads.s3.amazonaws.com/i/dmf89qktsogytnu03ppu.PNG)

**git clone**
This command is used to obtain or download a repository 
from an existing source.

![Alt git clone](https://dev-to-uploads.s3.amazonaws.com/i/yx4hxhkh0oeelzabvrbp.PNG)

**git add**
This command is used to add a single file or multiple files to a staging area. Note that, the added file(s) won't be on your remote environment until they're pushed.

 Here are some `git add` commands
 * `git add filename` adds a file called "filename" to the staging 
 area
 * `git add .` stages new files and modifications, without 
 deletions
 * `git add -A` stages all changes
 * `git add -u` stages modifications and deletions, without new 
 files

![Alt git add](https://dev-to-uploads.s3.amazonaws.com/i/3whluzzsnsngt17eadts.PNG)


**git commit**
This command records or snapshots the file permanently in the version history.

Here are some `git commit` commands
* `git commit -m "My First Commit"` gives you the opportunity to add a commit message.
* `git commit -a` commits any files you’ve added with the git add command and also commits any files you’ve changed since then.

![Alt git commit](https://dev-to-uploads.s3.amazonaws.com/i/fwub2eaib5cbhqrsinh2.PNG)


**git remote**
This command is used to connect your local repository to the remote server.

![Alt git remote](https://dev-to-uploads.s3.amazonaws.com/i/d10wedh9d7a13i8upowi.PNG)


**git status**
This command lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.

![Alt git status](https://dev-to-uploads.s3.amazonaws.com/i/xo3ekbjuc0b7q21hg0um.PNG)


**git fetch**
The command is a primary command used to download contents from a remote repository. This content includes branches and tags.

![Alt gitfetch](https://dev-to-uploads.s3.amazonaws.com/i/511c7t3bac1015qaet5l.PNG)


**git checkout**
This command is used to switch from one branch to another. 

![Alt git checlout](https://dev-to-uploads.s3.amazonaws.com/i/kh09yhfsgnll9670p7nz.PNG)


This command can be used to create a new branch. To create a new `git checkout -b my-new-branch` where "my-new-branch" is the name of the new branch.

![Alt git checkout2](https://dev-to-uploads.s3.amazonaws.com/i/wnnuhplvn21p8aa6248q.PNG)


**git push**
This command sends information committed  to your remote repository. when using `git push` you can there are multiple way commits can be pushed to the remote.

* `git push [remote-variable-name] [branch-name]` this command pushes commits staged on a particular branch to a remote origin, example `git push origin master` we can also have `git push heroku my-new-branch`.
* `git push all` this command pushes all branches to your remote repository.
* `git push -force` or `git push -f` this command forcefully send the current staged commit to the remote repository.
* `git push -u origin master` is used for pushing staged content to GitHub. In the code, the origin is your default remote repository name and `-u` flag is upstream, which is equivalent to `-set-upstream` and the master is the branch name.

![Alt gitpush](https://dev-to-uploads.s3.amazonaws.com/i/iprabjbkccvvltxm5egr.PNG)


**git pull**
This command fetches and merges changes on the remote server to your working directory.

![Alt gitpull](https://dev-to-uploads.s3.amazonaws.com/i/u52fcrp6uwc69il3ehym.PNG)


**git stash**
This command temporarily stores all the modified tracked files. this command can also be used to check all new modifications and move them to a new branch.

![Alt git stash](https://dev-to-uploads.s3.amazonaws.com/i/m7gax2k3hasc8d6ni7dc.PNG)

* `git stash pop` this command restores the most recently stashed files on the current branch.
* `git stash list` this command lists all stashed changes.
* `git stash drop` this command discards the most recently stashed changes.

**git merge**
This command merges the specified branch’s history into the current branch.

**git branch**
This command lists all the local branches in the current repository. This command can also be used to create a new branch or delete an existing branch.

* `git branch new-branch-name` this command creates a new branch called "new-branch-name".
* `git branch -d [branch-name]` this command deletes the feature branch.

![Alt git branch](https://dev-to-uploads.s3.amazonaws.com/i/2rl9mvfjrl72ejifasbf.PNG)


**git log**
This command is used to list the version history for the current branch.

![Alt git log](https://dev-to-uploads.s3.amazonaws.com/i/hbxg07b354y416uxqya0.PNG)


You can start by practicing these few git commands, using them constantly also helps to learn them faster. I hope you have a great learning experience. 

To get a more in-depth knowledge of git please click here [learn git](https://try.github.io/)