A beginner’s guide to Git Version Control — in terminal

Jules Grandury
4 min readApr 26, 2022

--

Prerequisites: A free Github account that you can easily sign up for here and git installed on your computer — more information on this here.

What is Git? Git is a version control system used by developers across the globe. It allows us to track different and continuously evolving versions of our code as well as collaborate on the same codebase with other developers.

What is Github? Github is not the equivalent of Git! It is a hosting service that allows users to host their Git projects on remote servers around the world. It is a product that integrates with git in the same way other companies — such as Bitbucket and Gitlab — offering hosting services do.

What is a Git Repository? Think of a repository as a folder or container tracking all of the changes made to the files in your project over time. You will encounter two kinds of repositories: the local repositories and the remote repositories. The local repository is on our computer while the repository residing in the cloud or on hosting services (such as Github and others mentioned above) is the remote repository. The remote repository is what allows us to backup our code in case something happens to our local copy or our computer as a whole, and what allows us to collaborate with other developers (using git branches).

The Basic Terminal Commands

  • pwd for print working directory — will print the path of the current directory you are working in
  • cd for change directory — will change directories based on the arguments that follow
    cd or cd~ will change the directory to the home directory of the user such as “/Users/name”
    cd / will change the directory to the root directory of the current drive. The root directory is the very first directory in your filesystem hierarchy.
    cd.. will change the directory to the parent directory of the current, this means it will go one directory back or up from the current directory
    cd name or cd “name" will change the directory to the directory named
  • ls for list — will list the names of all the files in the current directory excluding hidden ones
  • mkdir <name> for make directory — will create a new directory with the following name
  • touch <name> creates a new file with the following name in the current directory

The Basic git Commands for Terminal

  • To check that you have git installed, run this command in your terminal. This will give you the current version of git on your computer. If you do not have it installed it will prompt you to do so and you can find more information about that here.
$ git --version
  • Navigate to your project directory using the terminal commands discussed in the section above and create a git folder using the following command. This command will create the folder in your current working directory. Example: If I enter pwd and it /User/Julia/Desktop/Github_LocalReps/pokemon-app , this will create the git folder in the pokemon-app folder.
$ git init
  • Once you have initialized your git repository. You can use the following command to check if there is anything to commit at any point of the process.
$ git status
  • To add file changes in the current working directory to the staging area use the following command with the variations explained below.
$ git add
  • To add a specific file $ git add <filename>
  • To add all files with a specific extension, such as the .txt extension $ git add *.txt
  • To add everything $ git add *.*
  • To add everything within the current folder $ git add .
  • To add only the modified and deleted files to the staging area and ignore new files and folders $ git add -u
  • To commit the staged files run this command with a customized message within the quotation marks. After a successful commit, git status should return nothing to commit.
$ git commit -m "..."
  • To commit these changes to a remote repository you must create one on Github or a similar hosting service. When you create a new repository on Github, you will find yourself looking at a page like this. You can copy the link at the top (in the blue section) and input it into the following command.
$ git remote add origin <link copied from blue section>
  • You can then push your previously committed code to the remote repository using:
$ git push -u origin master
  • For more commands try:
$ git --help

Acknowledgements

Below are some articles and video tutorials I found helpful to bookmark and come back to when I first learned about git and Github.

Let’s chat! My email is always open at booleanjules@gmail.com. Please reach out if you see any mistakes or to offer suggestions.

Check out my website here!

--

--

Jules Grandury

Software Developer based in NYC passionate about AI for good, AI ethics, and blue/green tech