Git is a popular version control system that helps developers track changes in their codebase, collaborate with other team members, and maintain a history of all the changes made to the code. In this blog post, we will discuss some of the essential Git commands that every developer should know.
Git Commands:-
git config
The
git config
sets the author name and email address respectively to be used with your commits.git config –global user.name “[user name]” git config –global user.email “[email address]”
git init
The
git init
command is used to initialize a new Git repository. It creates a new.git
subdirectory in the current working directory and sets up the necessary files and directories for version control.Usage: git init example: git init /home/Documents/DEMO
git clone
The
git clone
command is used to create a copy of an existing Git repository. It downloads the entire repository, including all the files and history, to your local machine.Usage: git clone [url] example: git clone https://github.com/Puneet722/test.git
git add
The
git add
command is used to add changes to the staging area. The staging area is a temporary storage area where changes are held before being committed to the repository.Usage: git add [file] example: git add test_1.txt
git commit
The
git commit
command is used to create a new commit in the repository. A commit is a snapshot of the changes made to the code at a particular point in time. Each commit has a unique hash value that can be used to identify it.Usage: git commit -m “[ Type in the commit message]” example: git commit -m “this is my test commit”
git reset
The
git reset
unstaged the file, but it preserves the file contents. This command undoes all the commits after the specified commit and preserves the changes locally.Usage: git reset [file] Usage: git reset [commit]
git branch
The
git branch
command is used to create, list, or delete branches in the repository. A branch is a separate line of development that allows developers to work on different features or fixes simultaneously.Usage: git branch Usage: git branch [branch name]
git checkout
The
git checkout
command is used to switch between branches or create a new branch. It updates the working directory with the contents of the specified branch.Usage: git checkout [branch name] //switch from one branch to another Usage: git checkout -b [branch name] //creates a new branch
git merge
The
git merge
command is used to combine changes from two or more branches. It takes the changes made in one branch and applies them to another branch.Usage: git merge [branch name]
git show
The
git show
command shows the metadata and content changes of the specified commit.Usage: git show [commit]
~Puneet 🙃