☰
Current Page
Main Menu
Home
Home
Editing Git commands you must know
Edit
Preview
H1
H2
H3
default
Set your preferred keybinding
default
vim
emacs
markdown
Set this page's format to
AsciiDoc
Creole
Markdown
MediaWiki
Org-mode
Plain Text
RDoc
Textile
Rendering unavailable for
BibTeX
Pod
reStructuredText
Help 1
Help 1
Help 1
Help 2
Help 3
Help 4
Help 5
Help 6
Help 7
Help 8
Autosaved text is available. Click the button to restore it.
Restore Text
https://towardsdev.com/git-commands-you-must-know-d217bf710502 # Git commands you must know | Ludivine Achouri | Towards Dev [  ](https://medium.com/@la.dev?source=post_page---byline--d217bf710502--------------------------------) [  ](https://towardsdev.com/?source=post_page---byline--d217bf710502--------------------------------) Photo by [Yancy Min](https://unsplash.com/@yancymin?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/) Git is a very important tool for any developer. I had a hard time understanding it at first, and I’m sure some of you are still a bit lost. So here is a rundown of 13 important git commands to better manage your workflow. There are many more commands available that you can find [here](https://git-scm.com/docs), but these are the most useful and frequently used ones and they will definitely speed up your coding process. If you are not sure to understand what Git is, or if maybe you don’t know the difference between Git and Github, I have an article explaining everything available [here](https://medium.com/p/cba1ce44e7d7/). 1\. git clone ------------- If you want to clone a remote repository use : **_git clone <repository url>_** 2\. git init ------------ To start a new project in an empty repository or to initialize an existing project, use this command in the project root : **_git init_** 3\. git fetch ------------- With **git fetch** you will get the latest updates of the repository, changes in the code and the new branches that were created. 4\. git checkout ---------------- With this command, you can switch branches : **_git checkout_** **_<branch name>_** To create a new branch and switch to it : **_git checkout -b_** **_<branch name>_** 5\. git add ----------- This command selects the files you updated, and that you wish to send to the remote repository. You can add a specific file with **_git add_** _<_**_file path>_** or add all the files with **_git add -A_** _or_ **_._** 6\. git stash ------------- If there are files that you don’t wish to commit now, you can set them aside or “stash” them. You first need to add them with the previous command, and then use **_git stash_**_._ To revert those changes, use **_git stash apply_** . 7\. git commit -------------- Once you made some changes in the code and you saved it, you have to **commit** them. You are creating a little “container” of updates that you describe with a message : **_git commit -m_** **_“commit message”_** Example : **_git commit -m_** **_“added a new react component”_** 8\. git push ------------ This command will send your commits to the remote branch : **_git push_** 9\. git revert -------------- You can revert commits you created. In order to do that, you will need to know the hash code of the commit. To get that hash code, use the command **_git log — oneline_.**  This will display a list of commits you previously created alongside a little code, that’s what you are looking for. If I wanted to revert that first commit, I will use the command **_git revert 7804f7c._** Exit the screen that will appear with **shift + q** or type **:qa** in the terminal. A new commit will created reverting the last changes without deleting the previous commit.  10\. git pull ------------- Using **_git pull_** will fetch all the changes from the remote repository and merge any remote changes in the current local branch. 11\. git branch --------------- **_git branch_** gives you the list of all the branches of the repository. You can also create new branches like this : **_git branch <new branch name>_** You can delete a branch as well : **_git branch -d <branch name>_** 12\. git status --------------- The **_git status_** command gives you information about the current branch. You will know if the current branch is up to date, if you need to **push**, or **pull,** if content is **staged, unstaged** or **untracked** and if files were **created, modified** or **deleted.** 13\. git merge -------------- **Git merge** is the command that “merges” or combine branches commits. Once you are done working on your branch, the last thing to do is to merge your branch with the main branch. First you need to be on the branch you want your branch to be merged into. **Example** : If you want to merge your branch **_“my-new-feature”_** into the branch called ”**main**”, you need to checkout into **_“main”_** and run the command here. If you don’t remember how to switch branches, type : **_git checkout main_** Before merging branches you should **_always_** fetch the latest updates: **_git fetch_** Now, you can merge you branch into the main branch : **_git merge my-new-feature_** Knowing these commands is very important, but I also advise you to use a software to manage git. [Github Desktop](https://desktop.github.com/) is available for free to handle your GitHub repositories. You can find other alternatives like [GitKraken](https://www.gitkraken.com/). I hope my article helped you understand all of this a little bit more ! Please don’t hesitate to ask questions if you need !
Uploading file...
Edit message:
Cancel