The Wayback Machine - https://web.archive.org/web/20241001055357/https://www.geeksforgeeks.org/useful-github-commands/
Open In App

List of Useful Git Commands

Last Updated : 20 Mar, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Git is a version control system that helps programmers and developers manage and track changes to their code at any time. It allows multiple people to work on a project simultaneously and also keeps track of who made what changes and when. Git stores these changes in a repository.

List of Git Commands

List of Top Useful Git Commands

Git commands are crucial for efficient collaboration and project management. In this article, we’ll explore a list of important Git commands like git commands to push, git commit command, git pull command, and git push command, etc that will help to improve workflow and optimize productivity. These are a Git Commands list that can be used frequently on Git.

1. git help

Take help from the Git help section for different commands and other errors.  

git help


2. git config

To set the basic configurations on Git like your name and email.

git config


  3. git config –-global user.name “ ”

Sets configuration values for your user name on git. 

git config –-global user.name “Ashish Madaan”


4. git config –-global user.email ” “

Sets configuration values for your user email on git.  

git config –-global user.email ashishmadaan6@gmail.com


5. git config –-global color.ui

To see different colors on the command line for different outputs.  

git config –-global color.ui true


6. mkdir

Create a directory if not created initially. 

mkdir store


7. cd

To go inside the directory and work on its contents.  

cd store


8. git init

To create a local git repository for us in our store folder. This will help to manage the git commands for that particular repository.  

git init


9. git status

To see what’s changed since the last commit. It shows all the files that have been added and modified and are ready to be committed and files that are untracked.  

git status


10. git add Readme.txt

To add a file Readme.txt to the staging area to track its changes.  

git add Readme.txt


11. git commit -m “ ”

To commit our changes(taking a snapshot) and provide a message to remember for future reference.

git commit -m “Created a Readme.txt”


 12. git log

To check the history of commits for our reference. 

git log


13. git add

To add a specific list of files to the staging area.  

git add


14. git add –all

To add all files of the current directory to the staging area. 

git add --all


15. git add *.txt

To add all text files of the current directory to the staging area.

git add *.txt


  16. git add docs/*.txt

To add all text files of a particular directory(docs) to the staging area. 

git add docs/*.txt


17. git add docs/

To add all files in a particular directory(docs) to the staging area.

git add docs/


 18. git add “*.txt”

To add text files of the entire project to the staging area. 

git add “*.txt”


19. git diff

To figure out what changes you made since the last commit.

git diff


 20. git reset head license

To undo the staging of the file that was added in the staging area.

git reset head license


21. git checkout –license

To Blow away all changes since the last commit of the file.

git checkout –license


22. git commit -a -m “ ”

To add any of our tracked files to the staging area and commit them by providing a message to remember.

git commit -a -m “Readme.md”


23. git reset –soft HEAD^

To undo the last commit and bring the file to the staging area.

git reset –soft HEAD^


 24. git reset –hard HEAD^

To undo the last commit and remove the file from the staging area as well(In case we went horribly wrong).

git reset –hard HEAD^


25. git reset –hard HEAD^^

To undo the last 2 commits and all changes.

git reset –hard HEAD^^


26. git remote add origin

These commands make a bookmark which signifies that this particular remote refers to this URL. This remote will be used to pull any content from the directory and push our local content to the global server.

git remote add origin https://github.com/madaan123/MyAlgorithms.git


27. git remote add <address>  

To add new remotes to our local repository for a particular git address.

git remote add <address> 


 28. git remove rm

To remove a remote from our local repository.

git remove rm


29. git push -u origin master

To push all the contents of our local repository that belong to the master branch to the server(Global repository).

git push -u origin master


30. git clone https://github.com/madaan123/MyAlgorithms.git

To clone or make a local copy of the global repository in your system 
(git clone command downloads the repository and creates a remote named origin which can be checked by the command – git remote -v). 

git clone https://github.com/madaan123/MyAlgorithms.git


31. git branch Testing

To create a new branch named Testing.

git branch Testing


32. git branch

To see all the branches present and current branches that we are working on.

git branch


33. git checkout Testing

To switch to branch Testing from the master branch. 

git checkout Testing


34. ls

To see directories and files in the current directory.  

ls


35. ls -la

To see hidden directories and files within the current directory.

ls -la


36. git merge Testing

To merge the Testing branch with the master branch.  

git merge Testing


37. git branch -d Testing

To delete the Testing branch.  

git branch -d Testing


38. git checkout -b admin

To create a new branch admin and set it as the current branch.

git checkout -b admin


39. git branch -r

To look at all the remote branches.

git branch -r


40. git branch -D Testing 

To forcefully delete a branch without making commits.  

git branch -D Testing


41. git tag

To see the list of available tags. 

git tag


42. git checkout v0.0.1

To set the current tag to v0.0.1. 

git checkout v0.0.1


43. git tag -a v0.0.3 -m “version 0.0.3”

To create a new tag. 

git tag -a v0.0.3 -m “version 0.0.3”


44. git push –tags

To push the tags to the remote repository.

git push –tags


45. git fetch

To fetch down any changes from the global repository to the current repository.

git fetch


46. git stash

To move staged files to the stash area which is present in the staging area.

git stash 


47. git stash pop

To get back the files that are present in the stash area.

git stash pop


48. git stash clear

To clear the stash folder.

git stash clear


49. git rebase

Three tasks are performed by git rebase 

  1. Move all changes to master which are not in origin/master to a temporary area.
  2. Run all origin master commits.
  3. Run all commits in the temporary area on top of our master one at a time, so it avoids merge commits.
git rebase


50. git –version

used to show the current version of Git

git –version



Previous Article
Next Article

Similar Reads

Simple and Concise Git Commands That Every Software Developer Should know
As developer git is the most useful arena which is not operated directly so do we have git commands that become very crucial that one should know after having git installed in the local system. if not you must download git from here Download Git. If you need any help with the further installation process. So, Now let's start with the basic commands
4 min read
Top 15 Git Commands to Become a Pro Developer [2024]
Git is a distributed version control system and open-source software used by developers to manage different versions of source code by tracking changes in files. It is used by developers to work together on the same project from anywhere. Whether you are a professional developer or just starting your coding journey, Git is essential for becoming a
8 min read
Top 12 Git Commands for Every Developer
Git is a distributed version control system and open-source software. It enables developers to manage many versions of a source code with ease. You can use it to figure out who did what, when, and why. Git has become a must-have tool for any developer nowadays, and knowing Git commands is required for developers to fully utilize Git. There are hund
9 min read
Some Useful Tips for Choosing Best VPN and Recommended VPN Services
A VPN (Virtual Private Network) is a network that extends over many public networks connecting users "virtually" to a single network. This is done by utilizing a VPN client on the user's machine and VPN server(s). This simple application helps a user in many different ways: bypassing access restrictions, protecting sensitive data from eavesdropping
5 min read
10 Useful Python One Liners That Developers Must Know
Python is known for its easy-to-code and intuitive syntax. And one-liners are like the cherry on the cake which makes Python a more beautiful and beloved programming language. There are numerous features in Python Language and one of its most loved features is its one-liners. Writing Code in Python is already easy compared to other programming lang
10 min read
6 Most Useful Android Studio Plugins
Android Studio provides a platform where one can develop android apps for Android phones, tablets, Android Wear, Android TV. Android Studio is the official IDE for Android application development, and it is based on the IntelliJ IDEA. One can develop Android Applications using Kotlin or Java as the Backend Language and XML for developing frontend U
5 min read
Is Kaggle Useful in Finding a Machine Learning Job?
If you are in any way connected to the tech industry, chances are that you have heard of Machine Learning! It's the current cutting edge technology that has a wide range of applications in almost all sectors. And if you have heard of Machine Learning, chances are that you may be interested in learning more about it and enhancing your knowledge. Kag
5 min read
7 Most Useful Google Analytics Metrics For Web Developers
Google Analytics is like a private detective for your websites that tracks your customer behavior, user experience, device functionality, and many more aspects. It is simply like a go-to solution to monitor your website, that provides you with amazing information about your visitors. One of the most astonishing facts is that it's completely free of
5 min read
8 Useful Firefox Extensions For Ethical Hacking and Security Research
When performing penetration testing of any web-based application, the Mozilla Firefox browser is the most favorable browser for almost every Ethical Hacker and Security Researcher. Mozilla Firefox has proved itself a more featured browser than various browsers like Chrome, Safari, Opera, etc. One of the main reasons behind its popularity is the Mor
6 min read
7 Useful String Functions in Python
As one of the most popular programming languages, Python enables developers to use string functions that help them to perform various operations. For those who don't know, the string data carries 1 or 1> value (that can be any number, unique character, etc.) and later gets converted into ASCII code i.e. American Standard Code for Information Int
4 min read
8 Useful Testing Tools, Libraries and Frameworks For React Developers
We all know the love of developers for the most popular library React. It's easy to learn and it's easy to build the user interface of any website using React. If you're building an application no matter what you should test your application before serving it to the user. If you are a frontend developer working on the React library, you might have
7 min read
10 Most Useful Development Tools for Software Developers
Development tools for Software Developers or any other tech person not only help to create, maintain, and support web or mobile applications but also develop and deploy them by selecting an appropriate working environment. Tons of development tools are available out there but to identify a set of tools that contribute to your projects in a feature-
9 min read
Interesting Funny Commands in Linux
This entire article is all about showing off cool commands executable in the Linux terminal. This article is aimed at being a one-stop destination for all cool or you can say interesting funny commands in Linux to play. 1. The Matrix Effect: We all can agree on one thing that the falling down text effect from "The Matrix" movie is one of the best s
5 min read
7 Linux Commands For Managing Users
Linux is a fantastic platform that allows multi-user access options. Different users can access the same Linux OS for working simultaneously. A user account allows multiple people to access directories, terminals, the Internet, etc. There are three types of user accounts: User Account: This account is for general use with limited permissions.System
3 min read
11 pip Commands For Python Developers
Python has been preferred over all programming languages for technological advancement. It is one of the most lucrative programming languages that is used as the main programming language by more than 80%of developers. It is used for web development, mobile applications, hardware programming, and many more. Pip commands cannot be ignored when we ta
5 min read
25 Basic Linux Commands For Beginners
While performing a task, we all need shortcuts. Shortcuts help us to complete a task quickly. Linux comes with such commands which are one to two words, using that commands, you can perform several operations in no time. As a beginner, you must be aware of those basic Linux commands to complete an operation in a short time in the Linux-based operat
13 min read
Top 10 Docker Commands You Need to Know
Docker has changed the goalposts of application development and deployment by providing a standard environment to run the applications, which is independent of their place of deployment. Moving forward into 2024, as a developer and DevOps engineer, one has to fully understand and know how to use appropriately the basic Docker commands. This article
7 min read
An Ultimate Guide to Git and Github
Highlights of the article: Introduction to GitGit Repository StructureGithubAccessing Github central repository via HTTPS or sshWorking with git - Important Git commandsIntroduction to Git For installation purposes on ubuntu, you can refer to this article: How to Install, Configure and Use GIT on Ubuntu? Git is a distributed version control system.
8 min read
Best Git Practices to Follow in Teams
We all know that Git is one of the most popular version control used by developers all over the world. Developers are using it for many years but not all developers know the best practices for using it. There are several ways to use git to communicate with your team. You can use these git best practices from a small team of two to ten developers. W
6 min read
How Git Version Control Works?
Git... The most popular and common tool used by programmers in the programming world. Forget about this tool for a moment and just look at the picture given below... Flashback... Are you laughing?? (Yes! You're....) The above picture reminds you of your developer journey. This is how you tried to keep the backup of your files when you were scared o
11 min read
Take Advantages of Git and GitHub to Stay Motivated & Consistent While Coding
Coding can be a difficult and challenging task, but using tools like Git and GitHub can significantly enhance your motivation and consistency. These tools offer powerful features that help you manage your projects, collaborate with others, and maintain a steady workflow. Here’s how you can use Git and GitHub to stay motivated and consistent in your
4 min read
30 Most Important Git Terminologies That Developers Must Know
Git, a widely used version control system, is important for modern software development. Understanding Git terminologies is important for effective collaboration and version management. This article will cover the 30 Most Important Git Terminologies That Developers Must Know to navigate and utilize Git efficiently. The first version of Git was rele
10 min read
How to Prepare a Word List for the GRE General Test
Preparing a word list for GRE is very useful as it helps in last minute quick revisions. Here are few steps to prepare a word list for GRE: Choosing the right material: It is important to check the authenticity of the material, before starting the preparation. The more words an individual memorises, higher is the chance of succeeding. Choosing a co
2 min read
Dart Programming - List
In Dart programming, List data type is similar to arrays in other programming languages. List is used to representing a collection of objects. It is an ordered group of objects. The core libraries in Dart are responsible for the existence of the List class, its creation, and manipulation. Logical Representation of List The index of the element repr
4 min read
A Categorical List of programming languages
Programming languages are the formal language, with a set of instructions which provides the desired output. For implementing various algorithms in our machines we started using the Programming language. A set of specific instructions are used in programmable machines, rather than general programming languages. Computer programming languages are us
7 min read
List of basic AutoCAD Terminology
AutoCAD is Computer-Aided Design, which is used to design variety of drawings. It provides various kinds of tools with the help of which different kinds of drawings can be made and viewed easily. Basic AutoCAD Terminology : As, we know meaning of terminology is specific term used in any field. Here we are discussing about AutoCAD, so we are talking
4 min read
List of 10 Best Ad Blockers in 2024
As we navigatÐĩ through thÐĩ digital rÐĩalm, onlinÐĩ advÐĩrtisÐĩmÐĩnts havÐĩ bÐĩcomÐĩ an intÐĩgral part of our onlinÐĩ ÐĩxpÐĩriÐĩncÐĩ. HowÐĩvÐĩr, for thosÐĩ sÐĩÐĩking a morÐĩ strÐĩamlinÐĩd and unintÐĩrruptÐĩd browsing journÐĩy, best ad blockÐĩrs havÐĩ ÐĩmÐĩrgÐĩd as a valuablÐĩ solution.  In thÐĩ yÐĩar 2024, a plÐĩthora of ad blockÐĩrs havÐĩ stÐĩppÐĩd up thÐĩir gamÐĩ, offÐĩring ÐĩnhancÐĩd fÐĩat
12 min read
Richest Man in the World By 17th January 2024, Top Billionaire List
As of December 2023, the richest person in the world is Elon Musk, the CEO of electric car company Tesla and aerospace manufacturer SpaceX. He is currently worth an estimated $232.5 billion, according to Forbes. Musk surpassed Bernard Arnault of France, who is the CEO and chairman of luxury goods giant LVMH, to take the top spot in June 2023. Arnau
13 min read
Top 25 Software & IT Companies in Pune [2024 Updated List]
India has emerged as a leading centre of attraction for worldwide IT companies. The country has many computer sciences, and IT graduates to provide a steady supply of talent for the IT industries. Furthermore, India has a Robust IT infrastructure, including advanced telecommunication networks, excellent internet connectivity, and great technology p
15+ min read
Top 20 Programming Languages to Learn in 2024: A Complete List for Developers
Are you wondering which programming languages will dominate the tech world in 2024? Curious about which skills will be most in demand by employers? Or perhaps you're trying to figure out which programming language is the best fit for your career growth? The answers to these questions are more critical now than ever, as the right choice can shape th
15+ min read
Article Tags :