From f4eb3ed35f935fa81795c823b820fbcfed35de99 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Mon, 28 Jun 2021 19:52:20 -0400 Subject: Add initial git cheatsheet This adds the initial cheatsheet from the Git and GitHub Bootcamp. This is just a baseline commit and this cheatsheet needs more resources added as well as the overall layout should be adjusted as needed. --- .../static/images/events/github_diagram_1.png | Bin 0 -> 57693 bytes .../static/images/events/github_diagram_2.png | Bin 0 -> 84327 bytes .../events/pages/code-jams/git-cheatsheet.html | 135 +++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 pydis_site/static/images/events/github_diagram_1.png create mode 100644 pydis_site/static/images/events/github_diagram_2.png create mode 100644 pydis_site/templates/events/pages/code-jams/git-cheatsheet.html diff --git a/pydis_site/static/images/events/github_diagram_1.png b/pydis_site/static/images/events/github_diagram_1.png new file mode 100644 index 00000000..958618e4 Binary files /dev/null and b/pydis_site/static/images/events/github_diagram_1.png differ diff --git a/pydis_site/static/images/events/github_diagram_2.png b/pydis_site/static/images/events/github_diagram_2.png new file mode 100644 index 00000000..9b4c70dc Binary files /dev/null and b/pydis_site/static/images/events/github_diagram_2.png differ diff --git a/pydis_site/templates/events/pages/code-jams/git-cheatsheet.html b/pydis_site/templates/events/pages/code-jams/git-cheatsheet.html new file mode 100644 index 00000000..0bba0263 --- /dev/null +++ b/pydis_site/templates/events/pages/code-jams/git-cheatsheet.html @@ -0,0 +1,135 @@ +{% extends "events/base.html" %} + +{% load static %} + +{% block breadcrumb %} +
  • Events
  • +
  • Code Jams
  • +
  • Git & GitHub Cheatsheet
  • +{% endblock %} + +{% block event_content %} +
    +
    + +
    +
    +

    Installing Git & Other Useful Tools

    +

    +

    +

    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    +

    Common Git actions

    +

    I want to get a working copy of a repository...

    +

    git clone <repository URL> - You can get the URL from the repo's page + on GitHub.

    +

    I want to change which branch I'm working on...

    +

    git checkout <other branch name>

    +

    I want to make a branch...

    +
      +
    • Just create it: git branch <new branch name>
    • +
    • Create and switch to it: git checkout -b <new branch name>
    • +
    +

    I want to indicate which files/changes I want to commit...

    +
      +
    • git add <filename> to add a specific file.
    • +
    • git add <folder name> to add everything inside a folder.
    • +
    • git add . to add everything under the current folder.
    • +
    +

    I want to commit my code...

    +
      +
    • git commit will open a text editor for you to write the commit message + inside (recommended).
    • +
    • git commit -m "Title" -m "Description" to write the commit message in + the command-line.
    • +
    • git commit -a to commit all changes without running git add + first (be careful!).
    • +
    +

    I want to pull down the latest changes...

    +

    git pull if you are on the branch that was changed.

    +

    I want to push the changes I made...

    +

    git push (assuming you're on the right branch).

    +

    I want to merge my branch with a different branch...

    +
      +
    1. Make sure you're on the branch you want to merge *into*.
    2. +
    3. git merge <name of branch you want to merge *from*>
    4. +
    +

    For example, if you pulled new changes to the main branch, you can merge + them into your feature/add-title branch with git merge main.

    +

    If you have merge conflicts (you changed something that was changed in the other branch as well), + edit the conflicting parts to get a working version of the merge, and then commit.

    +
    +
    +
    +
    +

    Best Practices

    +

    Making a commit & commit message +

      +
    • Keep commits atomic -- meaning only commit the absolute necessary to get functional code.
    • +
    • Keep the commit title to 50 characters or fewer.
    • +
    • Always include a description that explains in greater detail what the change is and why the change was made.
    • +
    +

    +

    + Working Fast +
    + During a short sprint of work, like a code jam, your team will often be working concurrently and quickly. + Be sure to git pull <repository> frequently so your branches and work stay up to date. + Having to deal with conflicting merges is something you want to avoid where possible. +

    +
    +
    +

    Other Notes & Considerations

    +

    + git fetch <repository> vs git pull <repository> +
    + While it may seem like these two do the same thing on the surface, there is one very important distinction. + Fetching only tells your local repository if there are any changes which happened on the remote repository. + Pulling actually brings the changes into your local repository. +

    +

    + Switching branches with uncommitted code a.k.a. Stash +
    +

    Try not to checkout to another branch while you have uncommitted changes, unless you want to transfer those changes. + If you weren't planning on transferring the changes, this can cause unexpected results. If the uncommitted changes + create a conflict, git won't let you switch branches at all.

    +

    If you don't want to commit the changes yet, but still want to keep them for later, you can hide them away with + git stash, and then you can switch branches safely. To bring them back, use git stash pop.

    +

    +
    +
    +
    +
    +

    Useful Resources to Definitely Read

    +

    + Oh no, I've made a git mess +
    + Git and GitHub for Dummies +

    +
    +
    +
    +
    +{% endblock %} -- cgit v1.2.3