Skip to content

Instantly share code, notes, and snippets.

@arvindkgs
Last active May 3, 2021 05:52
Show Gist options
  • Save arvindkgs/20e16e031b9f07ece883279aa65ced37 to your computer and use it in GitHub Desktop.
Save arvindkgs/20e16e031b9f07ece883279aa65ced37 to your computer and use it in GitHub Desktop.
[Git] Git commands #cheatsheet #cli #git
# Switch to branch
git checkout branch
# Create new branch and move changes to new branch
git switch -c new-branch
# Merge into current
git merge branch
# branch current
git branch branch
# branch new from other and switch to it
git checkout -b new other
  1. git init on local folder
  2. Create new empty repository on remote without any files
  3. git remote add origin git@github.com:arvindgs/kinesisdemo.git
  4. git branch --set-upstream-to=origin/master master
  5. git add .
  6. git commit -m "Initial commit"
  7. git push
# Reset all changes added to staging
git reset HEAD -- .
# Undo stage
git restore --staged <files>
# reset to last commit
git reset
# options
--hard (NO UNDO)
# Replace prev commit
git commit -a --amend

To run git pull on all subdirectories below current dir -

  1. git config --global alias.all '!f() { ls -R -d */.git | xargs -P10 -I{} bash -c "echo {} && git -C {}/../ $1"; }; f'
  2. git all pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment