Git Crash Course 2021 with GitHub
Tags: github, git, webdev, devops
Published: 2021-09-19 19:44:17

Let's learn about git! This article is dedicated to beginners and ~~complete~~ crash course on git and GitHub to get you started with your first git project. I will provide some link at the end of this article, so you can deep dive even more.
[if you prefer video over article check this out](https://youtu.be/uaSsetG4U0k)

###What is Git?
* Git is free and open source distributed version control system.
* Git was created by [Linus Torvalds,](https://en.wikipedia.org/wiki/Linus_Torvalds) he also created [Linux Kernel.](https://www.kernel.org/)
* Git is designed to handle everything from small to very large projects with speed and efficiency.
* Git is easy to learn and has a tiny footprint with lightning fast performance.  

####what is version control?
Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.

Software developers working in teams are continually writing new source code and changing existing source code. The code for a project, app or software component is typically organized in a folder structure or "file tree". One developer on the team may be working on a new feature while another developer fixes an unrelated bug by changing code, each developer may make their changes in several parts of the file tree and at the end it all gets merged to a single source which can be deployed.

#####so, let's say you have a project that is deployed. Now, if you want to make any changes to that project for an instance adding an AUTH feature you would probably make a copy of the final version and then make any modification to that copy. That will serve two purposes: 1. you can test your code beforehand, and 2. you have now a history record of your initial codebase and the newer code base. 
This above process might just work for you if you are the only developer working on the project and you make modification to your code every now and then.

However, if you have hundred's of developers working on the codebase and every one making thousands of changes every day, you can clearly imagine the above process will be a mess. Git solves this issue.  

_on a side note_: why every software has a three number name, like: macOS Big Sur version- **11.0.1**?

_[Semantic Versioning 2.0.0](https://semver.org/)_ ⬅ check this out.

###installing Git:
_Install Git on Mac OS X_: There are several ways to install Git on a Mac. In fact, if you've installed XCode (or it's Command Line Tools), Git may already be installed. To find out, open a terminal and enter git --version.
```terminal
$ git --version git version 2.7.0 (Apple Git-66)
```

Apple actually maintain and ship their [own fork of Git,](http://opensource.apple.com/source/Git/) but it tends to lag behind mainstream Git by several major versions. You may want to install a newer version of Git using one of the methods below:


#####_Git for Mac Installer_
The easiest way to install Git on a Mac is with Homebrew:
1. Open your terminal and install Git using Homebrew:
    ```terminal
    $ brew install git
    ``` 
2. Verify the installation was successful by typing which git -- 
   version:
     ```terminal
     $ git --version git version 2.9.2
     ```
3. Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
   ```terminal
   $ git config --global user.name "Emma Paris"
   ```
   ```terminal
   $ git config --global user.email "user@email.com"
   ```

#####_Install Git on Windows_
1. Download the latest [Git for Windows installer.](https://git-scm.com/)
2. When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. The default options are pretty sensible for most users.

3. Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt).

4. Run the following commands to configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:

```terminal
$ git config --global user.name "Emma Paris" $ git config --global user.email "eparis@atlassian.com"
```

###Git repository
We will be working with GitHub. If you don't have an account, go ahead and open an account in [GitHub](https://github.com/). Alternatively if you prefer to use other services like bitbucket or GitLab, feel free to do so, for the most part they all works the same way.

1. click on the repository:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9dzlktvioiemy0q2yysn.png)
 
2. click on new:
   ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnvrhoc7vngkg1qqn06r.png)
3. On the next page, name your repo and choose the appropriate options. Optionally I always keep the add a README file unchecked because I usually add my own README.md file with the first commit and also it does give you the second screen shot where you can get some useful git commands.
   ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7hv5r0otu5vyilcbj7yq.png)

4. This is the page you get next if you unchecked the add README file.
   ![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wcv00ljg8zhrzkj1789.png)

as you can see the above instructions gives you a step by step commands to run in your terminal to get started. 
  
##### _The idea is to first initialize the git in your project file._ 
* git init will create a folder in your project directory and it 
   will be hidden because you would never have to open that file.
   ```terminal
      git init
   ```
* next command to run in the terminal is git status.
   ```terminal 
      git status 
   ```
git status will show you any untracked files meaning any file that has modification but git did not staged it yet. The files needs to be tracked will be in red.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/viz7pjkyu15lwmu8vz4x.png)
* next command to run is git add \<filename> or git add .
   ```terminal
      git add .
   ```
This . will stage all the files and you will be using this 
  method for the most part. If you want to just track one specific 
  file, simply change the . with the filename like 
  ```terminal
     git add app.js
  ```

  this command will change the color of the files to green meaning 
  these has been staged. You can check that by running git status 
  command again.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvwn7d9yof655gkv2709.png)


  _notice on step 3 git actually showing you which command to run 
  next_ 

* Next command to run git commit.
  ```terminal
     git commit -m 'first commit'
  ```
* By default git has the branch named as master. However we are going to change the name of the branch to main.
   ```terminal
      git branch -M main
   ```
* It's time to link our remote GitHub link to our git project with the bellow command.
   ```terminal
      git remote add origin https://github.com/w3tsa/git-crash-course-2021.git
   ```

* finally we are ready to push our code to the repo.
   ```terminal
      git push -u origin main
   ```

_There are two more commands I want to show you is `git clone <repo link>` which will clone down a repo from your GitHub to your local machine. The second one is `git checkout -b branch-name` which will create a separate branch for you to work on instead of main branch. 

checkout the video bellow.

{% youtube uaSsetG4U0k %} 

useful links:
1. Git - https://git-scm.com/
2. How to install Git - 
   https://www.atlassian.com/git/tutorials/install-git
3. Semantic Versioning 2.0.0 - https://semver.org/