Skip to content

Instantly share code, notes, and snippets.

@leolelego
Last active December 27, 2017 19:55
Show Gist options
  • Save leolelego/86b1b87deaadb7c4897156e6c372615f to your computer and use it in GitHub Desktop.
Save leolelego/86b1b87deaadb7c4897156e6c372615f to your computer and use it in GitHub Desktop.
Git Command Memo

Advanced

Detete Branch

git branch -d branch_name # Delete Local branch use -D for force
git push -d <remote_name> <branch_name> # Push the deletion

Rebase (Change git history)

git rebase -i <commit>

Update submodule

git submodule update --init --recursive

Bak to last commit / reset

git reset --hard # removes staged and working directory changes
git clean -f -d # remove untracked

List conflicted files

git diff --name-only --diff-filter=U

remove submodule

# http://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule
mv asubmodule asubmodule_tmp
git submodule deinit asubmodule    
git rm asubmodule
# Note: asubmodule (no trailing slash)
# or, if you want to leave it in your working tree
git rm --cached asubmodule
mv asubmodule_tmp asubmodule

Stash

git stash # stash current brand
git stash list # list existing stash
git stash apply # apply last stash
git stash apply stash@{n} # n -> number of stash
git stash pop # apply last stash

basics

Clone

git clone https://github.com/repourl.git

add files to index

git add path/to/the/file.md path/to/the/file2.md

# Add all files - be carful
git add .

Push - send to server

git push # if cloned
git push --set-upstream origin branchName # if new branch

branch

# Create branch form current state
git checkout -b bName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment