Skip to content

Instantly share code, notes, and snippets.

@uborzz
Last active October 11, 2023 14:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save uborzz/ec5000a3b921ce09c5acaad209371c0c to your computer and use it in GitHub Desktop.
Save uborzz/ec5000a3b921ce09c5acaad209371c0c to your computer and use it in GitHub Desktop.
Git commands easy & fast!

Basic: Add, commit and push!

  • git add .
  • git commit -m "yummie! bananas!"
  • git push origin master
    • -u (set upstream to use only git push)

Checks

  • git status
  • git diff HEAD / git diff --staged
  • git log

Useful: Initialize, set, pull, remove

  • git init
  • git remote add origin https://xxx.git
  • git pull origin master
  • git rm file

Branches: Create, Switch to, Merge, Delete.

  • git branch new-branch
  • git checkout new-branch
  • git checkout master
  • git merge new-branch
  • git branch -d new-branch

Create remote from actual

  • git checkout -b new-branch

Resets

  • git reset...
    • git reset . (Unstage changes)
    • git reset --soft HEAD^ (Undo last commit, changes into staging)
    • git reset --hard HEAD^ (Undo last commit + changes)
    • NOTE! HEAD^^ (last 2 commits) / NOTE2! HEAD~1 (last)
  • git checkout filename (Back to last commit state (discard changes))

Stash

  • git stash (Saves local changes)
  • git stash pop (Loads them)

Cache creds

  • git config --global credential.helper store (Dangerous, saves creds on disk)
  • git config --global credential.helper 'cache --timeout=300' (Doesn't ask creds for 300 seconds)
  • git config --global --unset credential.helper (Disables)

Other

  • git fetch (Refresh available changes from all branches (no pull))
    • git fetch branchname (from specified branch)
  • git commit --amend -m "new message" (Append to last commit, overwrites message)
  • git remote set-url origin https://xxx.git (changes remote address for origin)
  • git pull origin master --allow-unrelated-histories (merge unrelated histories)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment