Skip to content

Instantly share code, notes, and snippets.

@made-by-chris
Last active September 3, 2022 07:07
Show Gist options
  • Save made-by-chris/1854f336b889e92447e10f956ec69e36 to your computer and use it in GitHub Desktop.
Save made-by-chris/1854f336b889e92447e10f956ec69e36 to your computer and use it in GitHub Desktop.
git commands cheat sheet

git cheat sheet

  1. repos

  2. what's up

  3. commits

  4. looking around

  5. ⭐ feature branches (git flow collaboration)

  6. rebase issues

  7. remotes

  8. other cool tricks

repos

- to start a repository (am i in the right place on my computer? make a folder):

In a terminal, i'll jump to my user folder to start. then i should go into the right folder where i keep my projects (eg./Users/ME/projects). If it's an existing project i want to add git to, ill go into that sub-folder. if its not an existing project, i should make a folder for my new project in the right folder, in my projects folder. then i initialise git:

cd 
cd projects 
mkdir MY_NEW_PROJECT
cd MY_NEW_PROJECT
git init

- to check if i've accidentally made a git repository in the wrong folder:

- to delete a git repository i've accidentally made in the wrong folder:

- to download an existing repository (am i in the right place on my computer? don't make a folder):

what's up

- to check whats happening in git right now:

- to check which branch i'm in:

commits

- to add something to my shopping basket (add to staging area):

- to save my current work (make a commit):

- why I should't type git add .:

- what a commit message should contain:

- how often i should commit my work:

- reasons to commit my work:

- to check i saved my work before going a commit:

look for the black/white circle in the tab of any open files Visual Studio Code! That means they're unsaved.

looking around

- to see all the commits:

- to see where I have been in terms of travelling between commits:

- to compare the current commit to another commit:

- to travel to another commit:

- reason that i can't sometimes switch to a different commit or do a pull:

⭐ feature branches (git flow collaboration)

- to start making a feature (new branch):

- to continue making a feature after lunch break (rebase):

- to finish making a feature (rebase, push, pr):

- how often to merge a feature branch with main branch:

rebase issues

- why i use rebase instead of merge:

- some reasons and commands that cause a conflictto happen:

- what is happening during a rebase conflict in simple words:

- the steps to do during a rebase:

remotes

- to check where git is pushing code to (list all remotes):

other cool tricks

- to hide a file from git and ignore it forever ( so it never goes on github ):

- instead of diffing every changed line of code, show only filenames of files that changed:

- to visualise a tree of the git repository 🌳:

git log --oneline --abbrev-commit --all --graph --decorate --color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment