Skip to content

Latest commit

 

History

History
85 lines (58 loc) · 3.66 KB

Git-Commands.md

File metadata and controls

85 lines (58 loc) · 3.66 KB

Welcome to Top-18 Command!

How to check your Git configuration:

The command below returns a list of information about your git configuration including user name and email:

git config -l

How to setup your Git user email:

This command lets you setup the user email address you'll use in your commits.

git config --global user.email "[email protected]"

How to cache your login credentials in Git:

You can store login credentials in the cache so you don't have to type them in each time. Just use this command:

git config --global credential.helper cache

How to initialize a Git repo:

Everything starts from here. The first step is to initialize a new Git repo locally in your project root. You can do so with the command below:

git init

How to add a file to the staging area in Git:

The command below will add a file to the staging area. Just replace filename_here with the name of the file you want to add to the staging area.

git add filename_here

How to add all files in the staging area in Git

If you want to add all files in your project to the staging area, you can use a wildcard . and every file will be added for you.

git add .

How to add only certain files to the staging area in Git

With the asterisk in the command below, you can add all files starting with 'fil' in the staging area.

git add fil*

How to check a repository's status in Git:

This command will show the status of the current repository including staged, unstaged, and untracked files.

git status 

How to commit changes in the editor in Git:

This command will open a text editor in the terminal where you can write a full commit message.

A commit message is made up of a short summary of changes, an empty line, and a full description of the changes after it.

git commit

How to commit changes with a message in Git:

You can add a commit message without opening the editor. This command lets you only specify a short summary for your commit message.

git commit -m "your commit message here" 

How to commit changes (and skip the staging area) in Git:

You can add and commit tracked files with a single command by using the -a and -m options.

git commit -a -m"your commit message here"

How to see your commit history in Git:

This command shows the commit history for the current repository:

git log 

How to see your commit history including changes in Git:

This command shows the commit's history including all files and their changes:

 git log -p 

How to rollback the last commit in Git:

git revert will create a new commit that is the opposite of everything in the given commit. We can revert the latest commit by using the head alias like this:

git revert HEAD

How to switch to a newly created branch in Git:

When you want to use a different or a newly created branch you can use this command:

git checkout branch_name

How to list branches in Git:

You can view all created branches using the git branch command. It will show a list of all branches and mark the current branch with an asterisk and highlight it in green.

git branch

How to remove a remote branch in Git:

If you no longer need a remote branch you can remove it using the command below:

git push --delete origin branch_name_here