Getting Started with Git and GitHub
Published: 2022-11-26 16:29:07

Git is a version control system for tracking changes in computer files, and source code management.
There are three stages in Git, namely:

**Modified:** This means that you have changed the file but have not committed it to your database yet.
**Staged:** you marked a modified file in its current version to go into your next snapshot.
**Commit:** means that the data is safely stored in your local database.   

**Why use git?**
here are some reasons we use Git: 

1. Git helps if a developer makes a mistake or unwanted change in the file, he/she can simply revert it to the previous version.

2. Git tracks all the changes made to a project, including information on who made the changes and when it was made. This makes collaboration very easy.

**How to use Git:** 
Step 1: Download and install  [git](https://git-scm.com/downloads)

Step 2: [Create a GitHub Account](https://github.com/signup) 
GitHub helps you to push your website for others to see your code and also for them to help you with corrections, contributions, and give comments on your code. (https://www.github.com)

Step 3: Setup Git on your development environment

Open a terminal

1. for macOS 
press command + space and type terminal.

2. for Windows 
Click the search icon and type cmd.

then check what version of git you are using and if it's the latest one by pressing.  `git --version`.

After doing that you have to place your configuration setting example: name, email, default editor, and line ending.
In the configuration setting you can specify it at three different levels there are:

1. **System**: this setting apply to all the users in a current computer.
2. **Global**: this setting applies to all the repositories of the current user.
3. **Local**: this setting apply the repository in the current folder.

after knowing all of these next we specify what part to configure by writing these
for the user name
`git config ---global user. name "name"`
for user email
`git config ---global user.email "email@gmail.com"`

After structuring and styling your code with CSS, HTML, and JavaScript and your web page look good and you want to push it to GitHub, first of all, you need to make sure Git knows about it by letting git track it the step are :
1. **Initialize**:
This git command is used when you are working on a new project and would like to initialize git to the project in order to keep track of the changes made in the project. Use ` git init` to initialize git in a new project.

2. **Add**: 
As you're working, you change and save a file or multiple files. Then, before you commit, you must git add. This step allows you to choose what you are going to commit. Use `git add .` that is track all the files you were working on or `git add file name` to only track `file name`

3. **Commit**: 
After tracking your files with `git add .`, you will need to create a checkpoint (save your work locally) for reference purposes in the future. This is usually done when you complete a task.
Use `git commit -m "comment"` to create a commit.

4. **Create a new repository**
In your newly created GitHub account, click on the `new` button to create a new repository  

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8xxbbj6qgmbn3i37v4np.png)
5: **Push the commit to GitHub**
Your newly created repository should look like this

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4ns2yesa9o8hlgmbqtc.png)
Run the following commands to push your changes to GitHub
`git branch -M main
git remote add origin git@github.com:github-username/repository-name.git
git push -u origin main
`
Refresh the page to see your code on GitHub