Git Most Used Commands

Git commands for learning. Today I'm sharing the git commands list that will be helpful for those people who use git as their code version control system to maintain their codes. As a Software Engineer GitHub is my favorite code repo though in our office we do git in the Azure code repository, let me know your favorite one in the below comment box. 

Git Most Used Commands


Here is the git all commands with examples.

Configure Git:

git config --global user.name "Your Name"

change Your Name with the real name that you use in the git account.

git config --global user.email "Your Email"

Change Your Email with your git email.

You can also check your name and email if you already have configured git on your system.

git config --global user.name

git config --global user.email

To create a repository:

Initialize a project folder as a git repository.

git init

Download the repository into your local storage

git clone <https link or SSH key>

Remote Repositories

Display the connected remote repositories

git remote

To connect to the remote repository

git remote add origin <URL>

Push all the commits to the remote repository

git push <remote> <branch name>

Branches

List all the local branches of the repo.

git branch

Create a new branch locally.

git branch <branch name>

Delete the branch named branch_name.

git branch -d <branch_name>

Create and switch to the new branch.

git checkout -b <branch_name>

Switch to the branch which already exists.

git checkout <banch name>

Merge the provided branch with the current working branch

git merge <branch name>

Abort the actions if there are any conflicts.

git merge -abort

To observe Your Repository

Display the state of the working directory and the staging area

git status

To get status in short form

git status -s

Display changes between commits or between commit and saved files

git diff

Display commit logs and diff output each commit introduces.

git whatchanges

To make changes

Stage the unstaged file.

git add <file>

Stage all files together

git add .

To unstage files.

git reset

Commit stages files

git commit -m "<message>"

Revert back to previous commit

git reset -hard

Tak uncommited changes (staged and unstaged) and saves them away for later use. Later then reverts them from working copy.

git stash

What command I regularly use do to manage code daily? Write new codes or debug then:

git add .

git commit -m "message what i have done"

git pull

git push

Most of the time in message I use to write azure feature number, story or task and also some meaningful word what these codes actually do.

0 Comments