List of useful GIT Commands in Linux

Installation

sudo apt install git – installs GIT from repositories

Configuration

git config –global user.name “Your Name” – the name that will be added to commits and tags
git config –global user.email “[email protected]” – the e-mail address that will be added to commits and tags
git config –global color.ui auto – enables the colors in GIT output

Also read: How to use GIT in Linux

Starting

git init [project name] – creates a new local repository
git clone [project url] – gets a project from remote repository

Common

git status – shows the status of your work
git diff – shows the changes
git checkout – discards changes in working directory
git add – adds a file to staging area
git reset [file] – gets file back from staging area
git commit [-m “message”] – commits the changes added to staging area
git rm [file] – removed the file from working directory and adds deletion to staging area
git stash – puts changes into stash
git stash pop – applies the changes in the stash and clears its contents
git stash drop – clears the stash contents

Branching

git branch [-a] – lists all branches in repository
git branch [name] – creates a new branch
git checkout [-b] [name] – changes working directory to the mentioned one
git merge [from name] – Combines the specified branch with the current one
git branch -d [name] – removes branch

Tags

git tag – lists tags
git tag [name] [commit *] – creates a tag for current commit
git tag -a [name] [commit *] – creates a tag object for current commit
git tag -d [name] – removes a tag from repository

Review

git log [-n count] – lists commit history
git log –oneline –graph –decorate – shows references and history graph
git log ref.. – shows commits that are present on current branch and not merged into ref
git log ..ref – lists commits that are present on ref and not merged into current branch
git reflog – list operations made on local repository

Sync

git fetch [remote] – gets changes from the remote but does not update the branches
git fetch –prune [remote] – removes refs from remote
git pull [remote] – gets changes from the remote and combines current branch with it
git push [–tags] [remote] – pushes local changes to remote
git push -u [remote] [branch] – pushes local branch to remote repository

Reverting

git reset [–hard] [target reference] – switches current branch to the target reference
git revert [commit *] – createa a new commit, reverting changes from the specified commit

Ignoring

cat .gitignore
#Contents of .gitignore
/logs/*
!logs/.gitkeep
/tmp
*.swp

Previous articleUsing GIT in Linux
Next articleLinux Beginner’s Guide Part 1
A.Sulthan, Ph.D.,
Author and Assistant Professor in Finance, Ardent fan of Arsenal FC. Always believe "The only good is knowledge and the only evil is ignorance - Socrates"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments