Git is an open source distributed version control system for agile and efficient handling of projects of any size.
The basic steps for using Git are described below:
-
Install Git : Download the latest version of the installation package from Git's official website for installation.
-
Create a new Git repository : You can use the following command to create a new Git repository in the current directory:
git init
-
Add files to Git repository : Use
For example, to add all files to the staging area:git add
commands to add files to the staging area of a Git repository.git add .
-
Submit changes : Use
For example, submit code and add a description:git commit
the command to submit all changes in the temporary storage area to the Git repository.git commit -m "add new feature"
-
View commit history : Use
For example, to view the last five commits:git log
the command to view the commit history of a Git repository.git log -5
-
Create and switch branches : use
For example, to create a new branch:git branch
commands to create or list branches, and usegit checkout
commands to switch to new branches.
For example, to switch to a new branch:git branch new_feature
git checkout new_feature
-
Merge Branches : Use
For example, to merge a new branch into master:git merge
commands to merge content between different branches.git merge new_feature
-
Push to remote warehouse : Use
For example, to push code to a remote repository:git push
the command to push the changes in the local warehouse to the remote warehouse.git push origin main