Working with Git on the command line can be little bit tricky. To help with that, I’ve listed common Git commands in this article, what each one means, and how to use them. My aim is to make Git easier to use on a daily basis.
This "git config" command helps you to, Tell Git who you are by allowing you to configure the author name and email address to be used with your commits.
This command helps you to Create a new local repository or initialise existing project.
This command helps you to create a local working copy of an existing remote repository, this command uses to copy and download the repository to a computer. It is the equivalent of git init when working with a remote repository. Git will create a directory locally with all files and repository history.
This command uses to Add one or more files to staging (index):
To stage a specific file:
git add index.html
To stage an entire directory:
git add css
To add all files not staged:
git add .
This command records the changes made to the files to a local repository. For easy reference, each commit has a unique ID you can include a message with each commit explaining the changes made in a commit. This commit message helps you to find a particular change or understanding the changes.
git commit -m "<commit message>"
This command uses to send local commits to the remote repository. It requires two parameters: the remote repository and the branch that the push is for.
git push <remote_URL/remote_name> <branch>
git status command returns the current state of the repository.
git status will return the results related to current working branch. It shows the files in the staging area, but not committed. Or, if there are no changes it’ll return nothing to commit, working directory clean.
To determine what branch the local repository is on, add a new branch, or delete a branch.
Create a new branch
git branch <branch name>
List all remote or local branches
git branch -a
Delete a branch
git branch -d <branch name>
Imagine that you have different brach in your project,to start working in a different branch, use git checkout to switch among branches.
Checkout an existing branch
git checkout <branch name>
Checkout and create a new branch
git checkout -b <new branch name>
To get the latest version of a repository run git pull. This pulls the changes from the remote repository to the local computer.