Hi 👋 I'm a 15-year-old geek interested in Systems Programming 💻 Web Apps 🌐 and Artificial Intelligence 🤖
Git is a version control system developed in 2005 by Linus Torvalds (The creator of the Linux kernel) 😏 It helps you keep track of the code changes you have made to files in your project 😍 It comes with a large number of commands that you can use to manage your source code efficiently
In this article 📜 we'll go over the 20 most commonly used Git commands that every software developer should know
git config -l
The above command displays a list of information about your Git configuration 🤔 including username, email, default code editor, etc.
git config --global user.email "[email protected]"
The above command could be used to configure your email address 📧 Replace your email address with [email protected]
The above command can be used to initialize 😃 That is to create a new Git repository 😄 It can be used to convert an existing project to a Git repository 🤨 The above command creates a new .git subfolder in your current working directory that contains all the require metadata for the new repository
git add FILE
The above command adds a file to the staging area 📁 Be sure to replace FILE with the name of the file to be added to the staging area
git add .
The above command adds all files to the staging area
The above commands displays the status of the current repository including the current branch, the list of deployed, undeployed, and untracked files, etc.
The above command commits the changes to head 🙃 When executed it opens a code editor in the terminal where you can write a commit message
git commit -m "YOUR COMMIT MESSAGE"
This command lets you specify just a short summary for your commit message without opening the code editor ✏️ Replace "YOUR COMMIT MESSAGE" with your own commit summary which describes the changes in your commit
The above command displays a list of commit logs
The above command to display the list of all created branches in the local repository
git branch -d BRANCH
Use the above command to delete a Git branch ➖ Make sure to replace BRANCH with the name of your own branch 🙂🙃 Also don't forget to add the -d flag 🚩 It tells Git that you want to delete the specified branch
git branch BRANCH
Use the above command to create a new branch 😉 One thing we need to keep in mind is that Git does not automatically switch to this branch - you need to do this manually with the checkout command (See #14)
git checkout BRANCH
You can use the above command to switch to a newly created branch or to another branch
git checkout -b BRANCH
You can create and checkout a new Git branch in a single command by adding the -b option to the checkout command
git add remote "https://REPO_URL"
The command adds a remote repository to your local repository 😊 Make sure to replace REPO_URL with the actual URL of the remote and repository
You can use the above command to commit your changes to the remote repository
You can use the above command to pull the latest changes from the remote repository
The stash command allows you to temporarily park (stash) your uncommitted changes (Both staged and unstaged) to save them for later use
git stash pop
Use the above command to reapply changes parked with the stash command
And that's it 🤓 Those were the 20 Git commands I use most often
I hope you found this article useful - have fun 😅👋
Also Published on C Sharp Corner 🔗
Create your free account to unlock your custom reading experience.