Top Git Commands

Top Git Commands

Git Commands that are famous and can be used in daily life of a engineer.

Β·

3 min read

Well before I start firing you these commands, I assume you already have basic information about what is Git? and How it works?

For those of you who don't know about Git. Here's the short version to understand it.

Git is a Version Control System which tracks the changes of any given files or folders or repositories.

To make things clear, put it like this: There is one file in a folder then you make a change in that file then git will track that change. Hence if you want to revert the changed file then you can do easily with this.

Okay, Let's Move on to the Top commands.

Git Commands

  • To make Git work in any given folder or repo then we first need to initialize it.
$ git init 
# This will initialize git into given repo.
  • To check whether any files are modified or not, we hit
$ git status
# This is show you the status of all files which is inside that repo where git is initialized
  • Before making any website Live for Production we add that website to the staging environment (DEV or UAT), likewise, we stage the changes in git with
$ git add
# This is the base command for adding files in stage area.

$ git add .
# To be very specific, if we want to stage all changed files then we do this

$ git add filename
# If we want only some files to be staged, that's how we can do it.
  • Now after staging we capture the snapshot of that changes and add it to the history, hence we use
$ git commit
# The base command to commit the changes

$ git commit -m "first commit"
# In our day to day life we do this, we give a small description of given changes.
  • If we have any remote repository attached to local git then we can check that by
$ git remote -v
# This will show all remote repository attached to local repo.
# Generally we'll two link which says something like this:

# origin link (fetch)
# origin link (push)
  • Now to reflect our local changes into the remote repo we do this by hitting this command
$ git push
# The base command to push local changes to remote

$ git push origin master
# Generally we do this, the formate for pushing local changes to remote is

# git push <remote name> <branch name>

Example: 
$ git push heroku master # will push local changes to heroku
  • Now if we want to get the remote changes to local,
$ git pull
# This will pull all the changes and add it to local repo.
# It is branch specific, if we are in master branch then it'll pull from branch or if we are in development branch it'll pull from that branch.
  • If we want to change the branch from git then we do this,
$ git checkout
# The base command to change branch

$ git checkout <branch name>
# Normally we do this
  • To get the history of all commits
$ git log
# This command will give all the history of commits that you have done.
  • To clone or say download remote repo to local we hit
$ git clone
# Base command to pull the remote repo

$ git clone <remote repository link>
# Here link can be https or ssh.

Well, That's it for this Blog, Thank You for reading it.


By Vishwas Acharya πŸ˜‰


Checkout my other content as well:

YouTube:

Podcast:

Book Recommendations:

Did you find this article valuable?

Support Vishwas Acharya by becoming a sponsor. Any amount is appreciated!

Β