Top Git Commands
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:
Subscribe to my newsletter
Read articles from Vishwas Acharya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vishwas Acharya
Vishwas Acharya
Embark on a journey to turn dreams into digital reality with me, your trusted Full Stack Developer extraordinaire. With a passion for crafting innovative solutions, I specialize in transforming concepts into tangible, high-performing products that leave a lasting impact. Armed with a formidable arsenal of skills including JavaScript, React.js, Node.js, and more, I'm adept at breathing life into your visions. Whether it's designing sleek websites for businesses or engineering cutting-edge tech products, I bring a blend of creativity and technical prowess to every project. I thrive on overseeing every facet of development, ensuring excellence from inception to execution. My commitment to meticulous attention to detail leaves no room for mediocrity, guaranteeing scalable, performant, and intuitive outcomes every time. Let's collaborate and unleash the power of technology to create something truly extraordinary. Your dream, my expertise—let's make magic happen! Connect with me on LinkedIn/Twitter or explore my work on GitHub.