Github Git Cheat Sheet



The Git version control system (VCS) is an essential link in most developers’ toolchains. Created by Linus Torvalds in 2005 (to manage the source code for the Linux kernel), Git is now the predominant VCS for development projects and organizations worldwide. Originally intended as a low-level source control engine (on which higher-level VCSs could be built), Git now includes functionality that addresses a wide variety of high- and low-level use cases. Nonetheless, most individual developers use a fairly small subset of its features on a day-to-day basis. Attached are a set of Git “cheat sheets”, published by the 3 main Git host services/vendors (GitHub, GitLab, Atlassian), providing quick references for the most commonly used commands and options. Also linked is an entire book on Git, available for free download.

Contribute to karlomr/Map-Git development by creating an account on GitHub. This Git cheat sheet saves you time when you just can't remember what a command is or don't want to use git help in the command line. It is hard to memorize all the important Git commands by heart, so print this out or save it to your desktop to resort to when you get stuck. Git Cheat Sheets. Reference sheets covering Git commands, features, SVN migrations, and bash. Available in multiple languages. GitHub: A cheat sheet by Jack Wallen in Developer on September 22, 2020, 7:44 AM PST GitHub is a code housing platform that allows developers to store their projects and network with peers.

Attachments

References

  • Legend: <> required, [] optional

Common Terminology

  • commit ≙ object with annotated changes in relation other commits
  • branch ≙ collection of commits
  • stage ≙ files earmarked for the next commit
  • HEAD ≙ reference to the top commit in the current branch
  • remote = bookmark for a repository origin (a repository may have several remotes)

Create & Clone

  • Clone an existing repository

    Default protocoll is SSH, eg. »git@example.com:repo.git«. HTTPS would be »https://example.com/repo.git«, another local repo »/home/user/repo.git«

    Creates a subfolder with the repo, if the folder name is not given, then the repo name is used (»foo.git« = »./foo« subfolder)

  • Create a new local repository

    If a folder name is given, a subfolder is created, otherwise the current folder is used

  • Send existing local repository to remote

  • Special: Create an empty repository on a remote server

    Connect with the remote server first

    The remote repository has to be »bare« (does not contain a working filetree, but a special .git subdirectory only) in order to accept a push

Show changes

  • Show working status - show current branch name and changed or new files

    Hint: Set a short alias for often used commands, like git st for git status → see »Configuration«

  • Difference between HEAD and files not yet staged

    Note: This ignores new files = files which were not added to the repository yet and therefore arent »tracked«

  • Difference between HEAD and staged files

  • Difference between HEAD and all files (staged and not staged)

  • Difference between branches, two commits, etc

    »+« line does exist in »bar« but not in »foo«, »-« reverse

  • Difference to another branch and show names of changed files only

  • Show all commits of current branch which are not merged into another branch

    The reference may be a branch or a tag, note the two dots at the end

  • Show branches in which one commit exists

Show history

  • Show all commits of current branch

  • Tunnel workspace one apk. Show all commits of current branch and names of each changed file

  • Show commits and each difference for a specific file

  • Examination: Show who changed what and when in a file

    Left side shows the last commit ID for the content on the right side

  • Show a single commit and its differences

  • Show all commits with a certain word in the commit message

Commit

  • Stage all (even untracked) files

  • Stage a tracked and modified file

  • Add hand-picked changes in a file to the next commit (≙ partial commit)

    yYes, add this part to the next commit
    nNo, skip this part
    dDon’t add this and all remaining parts of the file
    sTry to split the current part into smaller ones
    eManually edit the part

  • Stage all changes in tracked files and start a commit

  • Commit all previously staged changes

Branches

  • List local branches

    * marks the current branch

  • List remote branches

    use -a to show local and remote branches at once

  • Switch to a different branch

    -t checkout a new branch based on remote branch and save their connection

  • Create a new branch based on HEAD

    use git checkout -b <branch> to create a branch and switch right into it

  • Create a new branch based on a remote branch

    use --no-track to create a new branch based on a remote branch, but don't save a connection between both

  • Connect a remote branch with a local branch

  • Show merged branches

    --no-merged will show branches not merged yet

  • Delete a local branch

    -d will only delete the branch if it is merged with its remote branch (if set), -D will force the deletion

  • Delete a remote branch

Tags

Use tags to save a specific version (the commit relations up to this point) of a project. Merging older commits into the branch afterwards hence wont affect the tag.

  • Show all tags

    -l will show tag names only, -n<num> will add a number of lines from the annotation (default is one)

  • Mark the current commit with a tag

    Hint: Use semantic version numbers as tags

Update

  • Download all changes from , but don't merge to HEAD yet

    A manual merge is required now

  • Download changes and directly merge to HEAD

    If the connection between remote & local branch is saved, then git pull is sufficient

  • List all currently configured remote repositories

  • Show information about a remote, eg. which branches exist in this remote

  • Remove stale remote branch trackings (outdated connections)

    Remove connections to branches deleted on the remote by now - does not delete the local branch

  • Add a new remote repository

Github Git Cheat Sheet

Publish

  • Push local branch or tag to remote

    use »-u« to push the branch and automatically save the connection between local & remote

  • Push all local branches to remote

  • Push all tags to remote

Github Tutorial For Beginners Pdf

Merge

  • Merge a branch into your current HEAD

  • Manually solve conflicts and mark file as resolved

  • Use a tool to solve merge conflicts

    will use tool set in »merge.tool«, use »-t « to start a custom tool

  • Use a merge strategy

    »recursive« is the default merge strategy when pulling or merging one branch, so this param may be redundant
    »ours« merge commits but try to ignore all conflicting changes from the other branch
    »theirs« merge commits but try to ignore conflicts introduced by the own branch
    »patience« will cause GIT run rather time-consuming intelligent merge routines to avoid merge conflicts and errors in the first place

  • Cancel merge

Rebase

Use rebase with care! It will rewrite the history and therefore requires additional efforts when working with a team! Dont rebase unless every project member knows about the required workflow!

  • Rewrite commits from HEAD until given commit

    Opens an editable rebase command list - reorder the commands to change commit order, remove a line to delete the commit, change the preceded keyword to change the command

    p|pickkeep commit
    r|reworduse commit, but edit the commit message
    e|edituse commit, but halt the rebase sequence to change the commit (use git commit --amend -a)
    s|squashuse commit, but meld into previous commit

  • Rebase your current HEAD onto

    Merges all commits of given branch and applies new commits of the local branch on top (creates new commit IDs for these)

  • Abort a rebase

  • Continue a rebase after resolving conflicts

Stash

Use stash to save all current changes to a clipboard and retrieve them later.

  • Stash all changes away

  • Show all available stashes

    »stash@{0}« is the rather unreadable name of the stash state, where 0 is the latest

  • Retrieve a state form the stash list

    default is »stash@{0}«, use git stash pop <stash-name> to apply changes and remove the state from stash list

  • Remove a state from the stash list

    Onenote to word converter online. Gem Save OneNote Page as Word Document Gem's feature - ' Save Page as Word Document ' is in ' Gem ' tab - ' Save As ' menu. You just simple specify the document file name, Gem will save current page as a Word document, and convert the headings in page to Word headings. Click inside the file drop area to upload ONENOTE file or drag & drop ONENOTE file. Click on Convert button. Your ONENOTE files will be uploaded and converted to WORD result format. Download link of result files will be available instantly after conversion. Open the OneNote file you want to convert, click the 'File' menu and click 'Export' to bring up the.

  • Remove all the stashed states

Github Git Cheat Sheet

Revert

Git is merciful and lets you undo allmost all changes with ease.

  • Clear stage (≙ unadd files)

  • Discard all changes

  • Change the last commit

    Replaces the last commit (new ID), so it should only be used if the modified branch was not pushed yet

  • Special: Change author of the last commit

  • Remove the last commit but keep all files and changes

    Removes the last commit from the local history

  • Revert a commit (≙ apply inversion)

    Inverts changes of the given commit, applies them to the working directory and starts a new commit

  • Undo a local merge

    Use only if the branch wasn't pushed yet, otherwise rebase or revert

  • Remove a file

    Removes the file from the git repository index but keeps it on the file system

Configuration

  • Get configuration option

  • Set configuration option

    »local« will write to ».git/config« in current repository, »global« to »~/.gitconfig» and »system« to your systems »/etc/gitconfig«

  • Set username and e-mail

  • Ignore mode changes (chmod)

  • Set alias »st« for »status«

Github Git Cheat Sheet

Commit Message Format

shortened, detailed example at http://is.gd/commitformat

Best practices

  • Commit related changes
    • Each commit should adress one logical unit. Two different bugs should result into two commits.
  • Commit early & often
    • Keep your commits small and comprehensible, split large features into logical chunks.
  • Test code before committing
    • Make sure the code works, don't guess. Or let tools test your commit automatically. Revert faulty commits if necessary.
  • Don't commit half-done work
    • Commit only complete, logical changes, not half-done chunks. »Stash« changes if applicable.
  • Don't commit hot files
    • Don't commit configuration files (commit a config template instead), personal data, temporary files (GIT is no backup system) or things that can be regenerated form other commited things.
  • Write good commit messages
    • Help others to understand what you did (Motivation for the change? Whats the difference to the previous version?)
    • Useless commit messages may be forwarded to whatthecommit.com
  • Write in imperative present tense («change», not «changed» or «changes»)
    • A commit is a set of instructions for how to go from a previous state to a new state, so you should describe was the commit does and not what it did to your repository.
  • Don't panic
    • GIT lets you undo, fix or remove a bunch of actions
  • Don't change published history
    • GIT allows you to rewrite public history, but it is problematic for everyone and thus it is just not best practice to do so.
  • Use branches
    • Branching is cheap. Use separate branches for each bugfix, feature & idea. Make branching a part of your local workflow.
  • Merge regularly
    • Don't merge a huge feature into the master, instead merge the master regularly with your branch.
  • Use conventions
    • As with every development process: use conventions. For naming of branches and tags, how to write commit messages, when to commit into what branch, etc.

Github Git Cheat Sheet Template

Sources

About

  • Supervisor: Dan Untenzu @pixelbrackets
  • License: CC-BY-SA 3.0
  • Download & Contribution: pixelbrackets.de/git-cheat-sheet