Git is a powerful version control system that helps developers track changes, collaborate seamlessly, and manage codebases efficiently. Whether you're working on a solo project or collaborating with a team, Git ensures your work is safe, versioned, and organized. So we’ll explore 50+ essential Git commands that every developer should know from basic configuration to advanced version control operations.
List of Top Useful Git CommandsGit 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 helpTake help from the Git help section for different commands and other errors.
git help //Get help on Git Commands2. git config
To set the basic configurations on Git like your name and email.
git config // Set config values3. git config –-global user.name “ ”
Sets configuration values for your user name on git.
git config –-global user.name “Ashish Madaan” //Set global username4. git config –-global user.email " "
Sets configuration values for your user email on git.
git config –-global user.email ashishmadaan6@gmail.com // Set global email5. git config –-global color.ui
To see different colors on the command line for different outputs.
git config –-global color.ui true // Enable color highlighting6. mkdir
Create a directory if not created initially.
mkdir store // Create a new directory7. cd
To go inside the directory and work on its contents.
cd store // Enter directory8. 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 // Initialize Git repo9. 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 //Check repo status10. git add Readme.txt
To add a file Readme.txt to the staging area to track its changes.
git add Readme.txt // Add Readme.txt file to the staging area11. 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” // Commit staged changes with a descriptive message12. git log
To check the history of commits for our reference.
git log // View commit history with details like author, date, and message13. git add
To add a specific list of files to the staging area.
git add // Add specific files to the staging area (must specify filenames)14. git add --all
To add all files of the current directory to the staging area.
git add --all // Stage all files (tracked and untracked) in the current directory15. git add *.txt
To add all text files of the current directory to the staging area.
git add *.txt // Stage all .txt files in the current directory16. git add docs/*.txt
To add all text files of a particular directory(docs) to the staging area.
git add docs/*.txt // Stage all .txt files inside the 'docs' folder17. git add docs/
To add all files in a particular directory(docs) to the staging area.
git add docs/ // Stage all files inside the 'docs' directory18. git add “*.txt”
To add text files of the entire project to the staging area.
git add “*.txt” // Stage all .txt files across the entire project (quotes handle globbing)19. git diff
To figure out what changes you made since the last commit.
git diff // Show file changes not yet staged for commit20. git reset head license
To undo the staging of the file that was added in the staging area.
git reset head license // Unstage the 'license' file that was previously added21. git checkout –license
To Blow away all changes since the last commit of the file.
git checkout –license // Discard local changes to 'license' file (revert to last commit)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” //Automatically stage tracked files and commit with a message23. git reset –soft HEAD^
To undo the last commit and bring the file to the staging area.
git reset –soft HEAD^ // Undo last commit, keep changes in staging area24. 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/MyAlgorithms27. 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 rm29. 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 master30. git clone https://github.com/madaan123/MyAlgorithms
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/MyAlgorithms31. git branch Testing
To create a new branch named Testing.
git branch Testing32. git branch
To see all the branches present and current branches that we are working on.
git branch33. git checkout Testing
To switch to branch Testing from the master branch.
git checkout Testing34. ls
To see directories and files in the current directory.
ls35. ls -la
To see hidden directories and files within the current directory.
ls -la36. git merge Testing
To merge the Testing branch with the master branch.
git merge Testing37. git branch -d Testing
To delete the Testing branch.
git branch -d Testing38. git checkout -b admin
To create a new branch admin and set it as the current branch.
git checkout -b admin39. git branch -r
To look at all the remote branches.
git branch -r40. git branch -D Testing
To forcefully delete a branch without making commits.
git branch -D Testing41. git tag
To see the list of available tags.
git tag42. git checkout v0.0.1
To set the current tag to v0.0.1.
git checkout v0.0.143. 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 –tags45. git fetch
To fetch down any changes from the global repository to the current repository.
git fetch46. git stash
To move staged files to the stash area which is present in the staging area.
git stash47. git stash pop
To get back the files that are present in the stash area.
git stash pop48. git stash clear
To clear the stash folder.
git stash clear49. git rebase
Three tasks are performed by git rebase
git rebase50. git –version
used to show the current version of Git
git –version
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4