# GIT & Github ## What is Version Control? > Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. So ideally, we can place any file in the computer on version control. ## What is Git? Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. Git is a Distributed Version Control System. So Git does not necessarily rely on a central server to store all the versions of a project’s files. Instead, every user “clones” a copy of a repository (a collection of files) and has the full history of the project on their own hard drive. This clone has all of the metadata of the original while the original itself is stored on a self-hosted server or a third party hosting service like GitHub. Git helps you keep track of the changes you make to your code. It is basically the history tab for your code editor(With no incognito mode ?). If at any point while coding you hit a fatal error and don’t know what’s causing it you can always revert back to the stable state. So it is very helpful for debugging. Or you can simply see what changes you made to your code over time. ## Git Terminology - #### Repo What is a Repo. ? Repo. is short for **Repository**, it is a collection of source code. - #### Working Directory - #### Staging Area - #### Local Repository - #### Remote Repository #### * the file in a **Working Directory** could have one of the following stges (i.e. statuses): - It begins with **modified** state: Which means the files with the updated changes are not yet stored in the local repository. - After that **unstaged** state: Which means the file is updated changes are not yet marked to be committed to the local repository and are not yet committed. - Then it would be **staged** state: Which means the files with the updated changes are marked to be committed to the local repository but not yet committed. - And we have the **committed** state: Which means that the changes you made to your file are safely stored in the local repository. ## Common Git Commands 1. `git add` is a command used to add a file that is in the working directory to the staging area. 2. `git commit` is a command used to add all files that are staged to the local repository. 3. `git push` is a command used to add all committed files in the local repository to the remote repository. So in the remote repository, all files and changes will be visible to anyone with access to the remote repository. 4. `git fetch` is a command used to get files from the remote repository to the local repository but not into the working directory. 5. `git merge` is a command used to get the files from the local repository into the working directory. 6. `git pull` is command used to get files from the remote repository directly into the working directory. It is equivalent to a git fetch and a git merge. ## Step 0: Make a GitHub Account. If you don’t already have one, you can make one [here](https://github.com/join). ## Step 1: Make sure you have Git installed on you machine. If you are on a Mac, fire up the terminal and enter the following command: `$ git --version` This will prompt open an installer if you don’t already have git. So set it up using the installer. If you have git already, it’ll just show you which version of git you have installed. If you are running Linux(deb), enter the following in the terminal: `$ sudo apt install git-all` If you are on Windows: **GET A MAC** Or you can go to this this [link](https://gitforwindows.org/) for more info on how to get it. ## Step 2: Tell Git who you are. Mention your Git username and email address, since every Git commit will use this information to identify you as the author. `$ git config --global user.name "YOUR_USERNAME" ` `$ git config --global user.email "im_satoshi@musk.com"` `$ git config --global --list # To check the info you just provided` ## Step 3: Let’s Practice Git - Create a new repository on GitHub. Follow this [link](https://github.com/new). Now, locate to the folder you want to place under git in your terminal. `$ cd <dir_name>` - Initialize Git: And to place it under git, enter: `$ touch README.md # To create a README file for the repository` `$ git init # Initiates an empty git repository` - Now go edit the README.md file to provide information about the repository. Add files to the Staging Area for commit: - Now to add the files to the git repository for commit: - $ git add . # Adds all the files in the local repository and stages them for commit OR if you want to add a specific file `$ git add README.md # To add a specific file` - Before we commit let’s see what files are staged: `$ git status # Lists all new or modified files to be committed` - Commit Changes you made to your Git Repo: Now to commit files you added to your git repo: `$ git commit -m "First commit"` ## Step 4: Multiple branches `$ git checkout <branch_name>` ## Extra Resources ### Git Documentation [here](https://git-scm.com/docs/git) ### GitHub Documentation [here](https://docs.github.com/en) ### Install GitHub Disktop [here](https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/installing-and-authenticating-to-github-desktop/installing-github-desktop)