Git Commands
Git Commands
git config
This command is used to configure an author name and email associated with your git
activities.
Usage: For configuring the author name globally.
git config –global user.name [name]
Usage: For configuring the author name locally.
git config user.name [name]
Usage: For configuring email addresses locally.
git config user.email [email address]
git config user.email [email address]
Usage: For configuring email addresses globally.
git config –global user.email [email address]
Example:
2. git init
This command is used to initialize a new git repository.
Usage: For initialising a new git repository.
git init [repository name]
Note: If you do not provide a name to the repository it defaults to .git .
Example:
3. git clone
This command is used to clone a remote git repository.
Usage: For cloning a git repository.
git clone [url]
Example:
4. git add
This command is used to add files to the staging.
Usage: For adding a particular file.
git add [filename]
Usage: For add all files to staging.
git add
Example:
5. git commit
This command is used to record a file permanently in the project version history. It is
a standard to add a message associated with the commit.
Usage: For committing your staged changes.
git commit -m [message]
Usage: For committing all the staged and unstaged changes till now. It is generally used
when you have already added your file changes to the staging area using the git
add command and need to add additional file changes to the the staging area with the
commit.
git commit -a
Example 1: For committing your staged changes.
6. git diff
This command is used to check the current file changes.
Usage: For checking all the unstaged file changes:
git diff
Usage: For checking all the staged file changes:
git diff -staged
Usage: For checking the files changes between two git branches:
git diff [first branch] [second branch]
Example 1: Check all unstaged file changes.
7. git status
This command is used to lists all the committed files.
Usage: For listing all the files that have been committed:
git status
Example:
8. git reset
This command is used to unstage a file from the staging area.
Usage: Unstage the files form staging area while keeping the file changes.
git reset
Usage: Reset a commit.
git reset [commit id]
Example 1: Unstage the staged changes.
Example 2: Resetting a commit.
9. git rm
This command is used to delete a specific file from the current working directory and
stages the deletion.
Usage: For deleting a specific file from the current working directory and stages the deletion.
git rm [filename]
Example: Deleting the file test3.txt from the staged changes.
12.git tag
This command is used to add a tag associated with a commit.
Usage: Adding a tag to a commit:
git tag [commit id]
Example: