Skip to content

Instantly share code, notes, and snippets.

@woile
Last active June 22, 2021 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woile/81c707aaee020ca5b6a0dbe6a2890b9b to your computer and use it in GitHub Desktop.
Save woile/81c707aaee020ca5b6a0dbe6a2890b9b to your computer and use it in GitHub Desktop.
Recipes for git

GIT

Create new local repo

Navigate to the desired folder where you want to start a new git project, using cd.

git init

Clone remote repo

Go to github.com, find your repository and click in the clone icon.

git clone {url}

Configure SSH keys

SSH keys are usuful to login to a git remote server without having to type you password.

You'll have to create a key and upload the public key to the server (github.com, gitlab.com, bitbucket.com, etc)

EMAIL=your_email@example.com
ssh-keygen -t ed25519 -C "$EMAIL" -f "$HOME/.ssh/$EMAIL"
cat "$HOME/.ssh/$EMAIL.pub"

Copy the output of the command and .pub file and then go to the website of your git provider, then to your account's settings and search for Add SSH Key.

WORKING LOCALLY

Add new files

git add {file}

or add everything

git add --all

Create new commit

git status  # check the file to be commited
git add {file1} {file2}
git commit -m "write a descriptive message"

Work in a NEW branch

git switch -c {branch_name}

Attention: use this when you want to create (-c) a new branch and work on it, if the branch already exist and you want to continue your work there, check the next one.

Work in an existing branch

git switch {branch_name}

WORKING WITH REMOTES

Add a remote

git remote add origin {remote_url}

List remotes

git remote -v

Pull stuff from a remote

git pull {remote_name} {branch}

Example:

git pull origin main

Push stuff to remote

This is usually done after create a commit

git push {remote_name} {branch}

Example:

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