GIT COMMANDS

Hemashree S

12 Git Commands

  • Git offers a variety of command-line tools and graphical user interfaces, but the command line is the only place where all Git commands can be executed.
  • The following commands will guide you in using Git through the command line.

Basic Git Commands

Here’s a list of the most essential Git commands commonly used on a daily basis.
  1. Git Config command
  2. Git init command
  3. Git clone command
  4. Git add command
  5. Git commit command
  6. Git status command
  7. Git push command
  8. Git pull command 
  9. Git Branch Command
  10. Git Merge command
  11. Git log command
  12. Git remote command
Let’s explore each command in detail.

1. Git config command

This command sets up the user profile. The `git config` command is the initial and essential command used on the Git command line. It configures the author name and email address for your commits and is also employed in various other scenarios.
Syntax
$ git config --global user.name "ImDwivedi 1"
$ git config-- global user.email"Himanshudubey481@gmail.com"

2. Git Init command

This command is used to initialize a local repository.
Syntax
$ git init Demo
The `init` command will create an empty repository. See the screenshot below. Git Commands

3. Git clone command

This command creates a local copy of a repository from an existing URL. If you want to clone a repository from GitHub, this command lets you duplicate it to your local directory using the repository's URL.
Syntax
$ git clone URL
Git Commands

4. Git add command

This command adds one or more files to the staging area (Index).
Syntax
To add one file
$ git add Filename

To add more than one file
$ git add*
Git Commands

5. Git commit command

The 'commit' command is used in two scenarios, which are as follows:

Git commit-m
This command updates the HEAD, recording or snapshotting the file permanently in the version history along with a message.
Syntax
$ git commit-m "Commit Message"

Git commit-a
This command commits all files that have been added with `git add`, as well as any changes made to files since then.
Syntax
$ git commit-a
Git Commands

6. Git status command

The 'status' command displays the state of the working directory and staging area, showing which changes have been staged, which have not, and which files are not being tracked by Git. It does not provide information about the committed project history—use 'git log' for that. Additionally, it lists the files you’ve modified and those that still need to be added or committed.
Syntax
$ git status
Git Commands

7. Git push command

This command uploads the content of a local repository to a remote repository. Pushing transfers commits from your local repository to a remote repository, complementing the `git fetch` command. While fetching imports commits into local branches, pushing exports commits to remote branches. Remote branches are configured using the `git remote` command. Caution is advised when pushing, as it can overwrite changes.
The 'git push' command can be used in the following ways.

Git push origin master
This command uploads changes made to the master branch to your remote repository.
Syntax
$ git push [variable name] master
Git Commands
Git Commands

Git Commands

Git Commands
Git push-all
This command pushes all branches to the remote repository.
Syntax
$ git push --all
Git Commands

8. Git pull command

The `pull` command retrieves data from GitHub by fetching and merging changes from the remote server into your working directory.
Syntax
$ git pull URL
Git Commands

9. Git Branch Command

This command displays a list of all branches available in the repository.
Syntax
$ git branch
Git Commands

10. Git Merge command

This command merges the history of the specified branch into the current branch.
Syntax
$ git merge BranchName
Git Commands

11. Git log Command  

This command is used to view the commit history.
Syntax
$ git log
Git Commands
By default, if no arguments are provided, 'git log' displays the most recent commits first. You can limit the number of log entries shown by passing a number as an option, such as '-3' to display only the last three entries.
$ git log-3

12. Git remote command

The 'git remote' command connects your local repository to a remote server. It allows you to create, view, and delete connections to other repositories, which function more like bookmarks than direct links. This command does not offer real-time access to those repositories.
Git Commands







Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send