Git can be used in a variety of ways. Git is compatible with a wide range of command-line tools and graphical user interfaces. All Git commands can only be executed from the Git command line. The commands listed below will assist you in learning how to use Git from the command line.
Basic Git Commands
Here is a list of the most important Git commands that are used on a daily basis.
- Git Config command
- Git init command
- Git clone command
- Git add command
- Git commit command
- Git status command
- Git push Command
- Git pull command
- Git Branch Command
- Git Merge Command
- Git log command
- Git remote command
Let's go over each command in detail.
Git config command
This command sets the user's preferences. The Git config command is the first and most important command on the Git command line. This command specifies the author name and email address that will be associated with your commits. Git configuration is also used in other situations.
$ git config --global user.name "ImDwivedi1" $ git config --global user.email "[email protected]"
Git Init command
This command generates a local repository.
$ git init Demo
The init command will create a new repository from scratch.
Git clone command
This command is used to create a repository copy from an existing URL. If I want to make a local copy of my GitHub repository, I can use this command to create a local copy of that repository in your local directory using the repository URL.
$ git clone URL
Git add command
This command adds a file or files to the staging (Index) area.
To add one file
$ git add Filename
To add more than one file
$ git add*
it commit command
The commit command is used in two ways. They are listed below.
Git commit -m
This command causes the head to change. It saves or snapshots the file in the version history and adds a message to it.
$ git commit -m " Commit Message"
Git commit -a
This command commits any files added to the repository with git add, as well as any changes made since then.
$ git commit -a
Git status command
The status command displays the current state of the working directory and staging area. It shows which changes have been staged, which have not, and which files are not being tracked by Git. It provides no information about the committed project history. You must use the git log for this. It also shows which files you've modified and which you still need to add or commit.
$ git status
Git push Command
It is used to transfer content from a local repository to a remote repository. The act of transferring commits from your local repository to a remote repository is known as pushing. It's similar to git fetch in that it imports commits to local branches while pushing exports commits to remote branches. The git remote command is used to configure remote branches. Pushing has the potential to overwrite changes, so it should be used with caution.
The git push command can be used in the following ways.
Git push origin master
This command pushes changes from the master branch to your remote repository.
Git push -all
This command commits all branches to the server repository.
$ git push --all
Git pull command
The pull command is used to get data from GitHub. It downloads and merges changes from the remote server into your working directory.
$ git pull URL
Git Branch Command
This command displays a list of all the branches in the repository.
$ git branch
Git Merge Command
This command is used to merge the history of the specified branch into the current branch.
$ git merge BranchName
Git log Command
This command examines the commit history.
$ git log
If no argument is passed, the Git log displays the most recent commits first. We can limit the number of log entries displayed by specifying a number, such as -3 to show only the last three entries.
$ git log -3
Git remote Command
The Git Remote command connects your local repository to a remote server. You can use this command to create, view, and delete connections to other repositories. This command does not allow you to access repositories in real-time.
If you have any doubt about the git command line. Don’t hesitate to contact us. Airo Global Software will be your digital partner.
E-mail id: [email protected]
Author - Johnson Augustine
Chief Technical Director and Programmer
Founder: Airo Global Software Inc
LinkedIn Profile: www.linkedin.com/in/johnsontaugustine/