Stella Rouzi
3 min readDec 4, 2020

--

Git 101 — Get started with a project

Photo by Glenn Carstens-Peters on Unsplash

A quick guide on how to get started with a git repository

Conventions used:

  • repo is short for repository
  • the words project and repository (or repo) are used interchangeably
  • remote repo refers to the repo that is available to all project members, and exists in a platform like GitHub or Gitlab
  • local repo refers to the repo that exists on a specific machine

Difference between a repository and a branch

A repository can be perceived as your project, while a branch is an independent workspace within the repository.

The repository contains multiple branches, and it has a main branch.

A branch allows you to work on a new feature, independently of the main branch, which may receive updates — new commits — from other contributors.

Which command to use

The following table compares the different available commands

  • for copying a repository and
  • sharing the changes of a branch

and which one to use depending on your scenario — the main factor is whether we are referring to a local repository or a remote repository.

Table — Git commands overview (getting started)

git init command is executed within a folder, and the content of that folder becomes the content of the — newly created — local git repository.

git clone uses the url of remote repository — you can grab that URL from the web location of the remote repository

The local part is always known — local repo and local branch are the ones we are currently in. We can use git status to find out where we are!

All commands need to be executed inside a local git repository except for git init and git clone, which are used to create a new repository.

In the other commands, the remote repo and the remote branch are defined by a placeholder name, called remote, which you define like this:

git remote add remote-repo-name url-of-remote-repo

The remote-repo-name can be anything we want! For example, let’s take the example of this remote repository https://gitlab.com/LearnWithStella/git101

  • the remote repository is called git101 and
  • it is hosted under the account/team called LearnWitihStella
  1. To clone the remote repository locally
git clone https://gitlab.com/LearnWithStella/git101

git clone creates a new folder with the name of the remote repository. We need to navigate within that folder (cd git101) so that we are inside our local repository.

2. To add a remote (ie a quick reference to a remote repository), so that I can interact with that remote repository

git remote add learnwithstella git101

3. To get any new changes that may have been added in the remote repo
(Assuming you are inside the appropriate local branch, git checkout master)

git pull learnwithstella master

4. To add new changes in the remote repo
(Assuming you are inside a local branch called quick-guide, git checkout -b quick-guide)

git push learnwithstella quick-guide

In the above command, quick-guide is the name of the new remote branch that will be created, by convention (and not necessity) we use the same name as our local branch.

--

--

Stella Rouzi

A combination of tech and psychology. Crafting the web with Ruby on Rails. Organizing conferences. Mentoring through GSoC and hands-on workshops