Skip to content

Instantly share code, notes, and snippets.

@bartdorsey
Last active September 16, 2022 15:24
Show Gist options
  • Save bartdorsey/bbfcfe31f65e6ef03d1e86475b301755 to your computer and use it in GitHub Desktop.
Save bartdorsey/bbfcfe31f65e6ef03d1e86475b301755 to your computer and use it in GitHub Desktop.
How to start a git based project

How to start a git-based project

If you already have a remote repository on gitlab or github

You will gather the "clone url" from the website and then use the following command.

git clone <clone url>

This will create a new folder containing the repository. The remote will already be connected, and the main branch will already be tracking the remote branch, which means you can simply use git push and git pull

If you are starting a brand new project from scratch

There are two approaches:

  1. Create the repo first on the website
  2. Create the repo first locally

If you choose option 1, you will do the same thing as using an existing repo, you will use git clone, so follow the instructions above.

However, if you choose option 2:

You initialize the git repo in a new empty folder and optionally tell it what you want the default branch name to be (often main)

git init -b <main branch name>

Then create a repository on the website, and grab the "clone url". Be sure to not initialize any files in the repo (like a README.md)

Then you will want to connect your local repo to the remote one, but adding a remote, specifying the name (by convention this is usually origin) and the clone url.

git remote add origin <clone url>

Then you'll want to make sure you've made a few commits (other wise git will not be able to push anything)

Then you can push, but you must specify the remote to push to. If you add -u or --set-upstream it will set up your local repo to "track" the remote one, allowing you to use git push and git pull without specifying the remote.

For example: to push to a remote named origin with a branch named main:

git push -u origin main

As you can see, this option takes way more steps. For this reason, I recommend just starting your repo on the remote website, instead of using git init

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment