Introduction to Git Commands and How to Use Them
Learning Git Commands: Basics and Usage

I Like to Learn and share new things to you guys! I will update my Tech Stacks over Time
Here we are going to learn about Git Commands What are they and How to use that
Basics of Commands:
git init
git add . or particular file name
git status
git commit -m "Your commit message like what are the changes that you made "
git restore --staged file name
git log
git reset (particular commit Hash code you want to remove from your History)
Git Init:
git init is a command used to initialize a new Git repository. When you run git init in a directory, Git creates a new repository in that directory with a .git subdirectory that contains all of the necessary Git metadata for version control.
Here are the steps you can follow to initialize a new Git repository using git init:
Open your terminal or command prompt.
Navigate to the directory where you want to create your Git repository using the
cdcommand.Run the command
git init. This will create a new Git repository in the current directory.You can now start adding files to your repository using the
git addcommand, committing changes with thegit commitcommand, and pushing changes to a remote repository with thegit pushcommand.
Git add . :
git add is a command used to add changes to the staging area in Git. It is the first step in committing changes to a Git repository.
To add all changes to the staging area, including new files, modified files, and deleted files, you can use the command git add .
The . specifies that Git should add all changes in the current directory and its subdirectories to the staging area.
To add a specific file to the staging area, you can use the command git add <file>, where <file> is the name of the file you want to add. For example, git add index.html would add the file index.html to the staging area.
You can also use wildcards to add multiple files at once. For example, git add *.html would add all HTML files in the current directory to the staging area.

How do we know the index.html file is actually added we can use another command to find that use Git status
Git status:
git status is a Git command that shows the current status of the repository. It provides information about which files have been modified, which files are staged for commit, and which files are not being tracked by Git.
When you run git status, Git will display the following information:
The branch you are currently on.
The status of each file in the working directory, including whether it has been modified, staged for commit, or is untracked.
Instructions for how to stage or unstage files, and how to commit changes.

Git commit:
git commit -m is a Git command used to create a new commit in the repository with a commit message. A commit is a snapshot of the repository at a particular point in time, and it includes the changes that were staged using git add.
The -m flag is used to specify the commit message that describes the changes being made in the commit. The commit message should be a brief summary of the changes being made, and it should be written in the present tense. For example, git commit -m "Add new feature to homepage".

git restore:
git restore is a Git command used to restore the contents of a file or directory in the working directory to the state it was in at a previous commit. It is useful for undoing changes that were made to a file or directory and restoring it to a previous version.
To unstage changes:
git restore --staged <path>will unstage the changes made to the file or directory at<path>and restore it to the state it was in at the last commit.

git log:
git log is a Git command that displays a list of the commit history for the current branch. It shows the commits in reverse chronological order, with the most recent commit listed first.
When you run git log, Git will display the following information for each commit:
A unique identifier for the commit, called the commit hash.
The author and date of the commit.
The commit message, which describes the changes made in the commit.
Add some more files to the project

git reset:
git reset is a Git command that is used to undo changes made to a repository. It can be used to unstage changes that have been added to the staging area or to uncommit changes that have already been committed.
Now i don't need Css i want to switch it before the css version so i can have only my Homepage
In git log there is a Hash code for the respective commit choose that hash code
git reset (Hash code)

okay so how can i connect my local git to GitHub
- create a GitHub account it is free if you don't have one

In Repository name create your folder name click create repository
After that you screen looks like this

copy that URL in top switch back to your command prompt
The command is git remote add origin https://github.com/karthykarthick/Homepage.git
Here remote means you are working with urls
Add means you are add a url
origin means that url name

- Now it is connected to my Repo to local Repo(folder)
- if you check your github account nothing changes your file is not visible
git push origin main:
git push origin main is a command used in Git to push the changes made to the local main branch to the remote repository named origin.
After entering the command in command prompt it will push your changes to GitHub Account

git pull:
This command is used to update your local repository with the latest changes from a remote repository. To pull changes from a remote repository, you can use the command git pull <remote> <branch>. For example, git pull origin main would pull the latest changes from the "main" branch of the "origin" remote repository.
lets make some changes in GitHub like add some new files and then try to pull that changes in local repo, Here i added styles.css in GitHub Repo

After running the git pull comand it will pull changes from the repo to your local repo



