- git init: This command is used to initialize a new Git repository in the current directory. For example, you can use the following command to initialize a new Git repository in the myproject directory: $ git init my-project
- git clone: This command is used to clone an existing Git repository from a remote source. For example, you can use the following command to clone the my-project repository from the https://github.com/user/my-project.git URL:
$ git clone https://github.com/user/my-project.git
- git add: This command is used to add files to the staging area in a Git repository. For example, you can use the following command to add the file1.txt and file2.txt files to the staging area:
$ git add file1.txt file2.txt
- git commit: This command is used to commit the changes in the staging area to the Git repository. For example, you can use the following command to commit the changes in the staging area with the commit message "Added new files":
$ git commit -m "Added new files"
- git push: This command is used to push the committed changes in the local repository to the remote repository. For example, you can use the following command to push the committed changes to the origin remote branch:
- git pull: This command is used to pull the changes from the remote repository to the local repository. For example, you can use the following command to pull the changes from the origin remote branch:
- git branch: This command is used to list, create, or delete branches in a Git repository. For example, you can use the following command to create a new branch called my-branch:
- git checkout: This command is used to switch between branches in a Git repository. For example, you can use the following command to switch to the my-branch branch:
- git log: This command is used to display the commit history of a Git repository. For example, you can use the following command to view the commit history with the author and date information:
$ git log --pretty=format:"%h %an %ad"
- git diff: This command is used to view the differences between two versions of a file in a Git repository. For example, you can use the following command to view the differences between the file1.txt file in the HEAD and the my-branch branch:
$ git diff HEAD my-branch file1.txt
- git stash: This command is used to save the local changes in a Git repository without committing them. For example, you can use the following command to stash the local changes:
- git tag: This command is used to add tags to specific commits in a Git repository. For example, you can use the following command to add a tag called v1.0 to the latest commit:
- git merge: This command is used to merge one branch into another branch in a Git repository. For example, you can use the following command to merge the my-branch branch into the master branch:
- git reset: This command is used to reset the state of a Git repository to a previous commit. For example, you can use the following command to reset the repository to the HEAD commit: