DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Code Something
Code Something

Posted on

Git in VSCode

I've been coding for some time now and still I find that I'm prone to forgetting even simplest of git commands (especially after moving to VSCode version control UI.)

Recently I was working on a project that required using git in terminal. So I wrote this article to remind myself how to do it πŸ™‚

Git tutorial: How to clone remote repository using git on command line

First…open your VSCode and go to View > Integrated Terminal. This will open the Terminal at the bottom of VSCode. This is exactly the same as running cmd.exe on Windows and Terminal on Mac.

Next you need to initialize the git repository. You can do this by typing git init in the terminal. This is a one time process. After this you can start staging, committing and pushing files to the repo. Now that you have initialized a git repository, you can start adding files to it.

To add a file, type "git add filename" in the terminal. You can also type "git addΒ ." to add all changed files. By doing this you are adding a file to something called "stage." Staging is a process of creating a set of changed files you want to include in your commit. It doesn't mean changes have been committed to the GitHub repository yet.

Once you have added a file that has been changed (or multiple files) you can commit it to the repository. To do this, type git commit -m "message" in the terminal. The message should be something describing the changes you are making. You can skip the message by not even including -m flag.

Now that you have committed your changes, you can push them to a remote repository. To do this, type "git push" in the terminal. At this point the files will be uploaded to your GitHub repository and will appear there within a few seconds. Other developers can now pull them from the repo, run the new code and start applying their own edits.

You can also pull changes from a remote repository. To do this, type "git pull" in the terminal. If someone else on the team pushed their own files to the repo, you will be able to get latest version this way. It's generally a good idea to do a pull before applying and staging your own changes.

These are the basic git commands that you will need to know in order to use git on the command line. For more information, consult the git documentation.

Here are some other git tutorials I found on YouTube:

Top comments (0)

Create an Account!
Now it's your turn!
Β 
πŸ—’ Share a tutorial
πŸ€” Reflect on your coding journey
❓ Ask a question

Create an account to join hundreds of thousands of DEV members on their journey.