Git commands are much cooler than what you think

Sharing is caring!

320 Views -

Hello Developers,
In this article we are discussing different git commands to use on the command console, these git commands can make Git easier to use in your daily life.
As a Developer-
A Git repository is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed.
Show the current configuration:

git config --list

Set git username and email

git config --global user.email "info@email.com"
git config --global user.name "name"

Clone an existing repository:

There are two ways:

Using SSH

git clone ssh://user@domain.com/repo.git

Using HTTP

git clone http://domain.com/user/repo.git

Versioning an existing project with a new git repository

git init <project directory>

Changes in the working directory:

git status

Changes to tracked files:

git diff

See changes/difference of a specific file:

 git diff <file>

Add all current changes to the next commit:

git add .

Commit with the message:

git commit -m 'your message'

Branches & Tags

List all local branches:

git branch

List local/remote branches

git branch -a

List all remote branches:

git branch -r

Switch HEAD branch:

git checkout <branch>

Get all changes from HEAD to the local repository:

git pull origin master

Publish local changes on a remote:

git push remote <remote> <branch>

Merge branch into your current HEAD:

git merge <branch>

Revert-

Revert the previous commit:

git revert HEAD
git commit

Stash-

Save a change to stash:

git stash save "stash name"

git stash

List all stashes:

git stash list

If you want to learn more, please check here(Reference)-
https://github.com/arslanbilal/git-cheat-sheet

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments