<Article/>
Command line Git commands every dev. should know.
General · Nov 27, 2022 · 3
0
While there are many ways to interact with Git; Github Desktop, VSCode source control panel etc, getting to have a few git tricks up your sleeves might make you a better developer or magician. You never know, you might just end up in an interview where you are required to work with git, there might be not vscode, github desktop or other sophisticated GUIs you are used to, but trust me, thereâs a pretty big chance thereâd most certainly be a command line.
- git -v or gitâââversion: This command returns the git version installed on your machine. Itâs a good trick to check if git is installed on your machine or not and if its not, you could get it here.
- git init : This command initialises a local git repository on your machine. Just navigate to your project directory and wave your git wandââââgit initâ and voila.
- git add . : Say youâve made a lot of changes in your project affecting multiple files, this command stages all files with changes and prepares them for commit and pushing to your online repository.
- git add file.extension : Say you want to only stage, commit and push just one file you have made changes to, this command helps you stage just one file. Just replace âfile.extensionâ in the command with your file name and extension. E.g git add index.js
- git commit -m âput your commit message hereâ : This command helps you commit your changes to your project history and add a message to it. It is commonly advised to use meaningful commit messages to help any other person who might have to work on your project sometime later, (Who knows, that person might be future you).
- git push : Great job staging and committing all your changes. This command is your magic word to move your changes from your local repository on your machine to a remote (online) repository.
- git clone : Say you are collaborating on an already existing project, to get a copy of that project on your own local machine, git clone + the url of the repository you are trying to clone, e.g git clone https://github.com/repo_owner/repository_name
- git fetch : This downloads files from an already existing repository but doesnât merge all changes but gives your an opportunity to look over them before integrating the new files into your project.
- git pull : This is just like git fetch, only that it downloads changes from an already existing repository branch and merges them with your local repository.
- git branch : This is a multi-purpose command. On its own, git branch returns all the branches on your repository. Quite useful when used with some other commands like git checkout, git pull, git merge, etc.
Certainly there are tons of other git commands every developer should know, but these few tricks could get you through a basic git work flow.
Here are some other resources that could help you learn more about git commands:
- Git Commands: https://www.atlassian.com/git/glossary
- Git Documentation: https://git-scm.com/doc
- Difference between git and github