Skip to content

Latest commit

 

History

History
59 lines (37 loc) · 3.41 KB

git-cheatsheet.md

File metadata and controls

59 lines (37 loc) · 3.41 KB

git cheatsheet

This page gathers some instructions around the git functionalities we'll use throughout the workshop, so feel free to consult at any time!

Clone

For full documentation on this command check the git docs.

  • To clone a repository follow the instructions on this GitHub article

Create a branch

This Git Branching doc is a very comprehensive guide to Basic branching and merging, and it's worth the read if you're new to git and it's architecture. Also, worth to know about GitFlow, which is one of the most used branching models (either pure GitFlow or some variation of it).

To create a new branch:

  1. git checkout -b <your-branch-name>

Change git core text editor

If you don't like to write your commit messages in a console text editor, you have the option to change which editor git opens up by default. To do so, run:

git config --global core.editor "<your-preferred-editor>"

For windows, for example, you can run the above command with "notepad.exe" as your preferred editor.

If you have changed this before, you might need to provide --replace-all to overwrite the configuration.

Commit

For more info on commits, see the docs and this useful article on Saving changes on git.

To commit new changes:

  1. Prepare the new files for the commit by adding them to the staging area:
  • git add <file-path>
  • If you have too many files to add (and are confident all files will need to be committed), you can opt for git add --all, which will add all the files into the staging area.
  1. Then, commit your code via git commit
  • You'll be redirected to a text editor to add your commit message.
  • If you're running it via Terminal within Visual Studio Code, you'll most likely have Vim as your editor.
    Type i to start editing, and when you're ready, type Esc, then :wq to save and exit.
    Alternatively, you can change git default text editor to something you're more comfortable with.
  • Add a proper description to your commit message. Keep in mind that this message will be kept in the repository history, therefore it needs to be clear and descriptive as to what it's addressing/implementing. Ex: Workshop1 - Adding generated react app.

Push

For more info on pushing your changes, see this GitHub article and the docs To push new changes:

  1. With all the changes committed, the next step is to Push the code to GitHub:
  • git push origin <your-branch-name> Important: The first time you Push your branch to a remote, you'll need to add the -u flag, which will tell git to create the branch remotely before pushing the code.

Useful links