Skip to content

Instantly share code, notes, and snippets.

@zhenyanghua
Last active June 14, 2017 15:41
Show Gist options
  • Save zhenyanghua/b2d2ab2b666d0c54dc1b71b9036778e5 to your computer and use it in GitHub Desktop.
Save zhenyanghua/b2d2ab2b666d0c54dc1b71b9036778e5 to your computer and use it in GitHub Desktop.
Git Cheat Sheet

pull the latest of the current branch

git pull

add all local changes to the stage and commit the staged local changes.

git commit –am “comments”

stash the local changes

git stash

pop the last local changes and apply to the current branch.

git stash pop

push the commit to the remote branch.

git push origin {target_upstream_branch}

merge the source branch to the current branch with all commit history.

git merge --no-ff {source_branch_to_merge_into_the_current_branch}

undo the commit, and remove file and from the stage, file itself won't change.

git reset {file_name} 

reset to some revision with 3 common options.

#Files won't change, differences will be staged for commit.
git reset --soft {some_revision}
#Files won't change, differences won't be staged.
git reset --mixed {some_revision}
#Files will be reverted to the state of the selected commit, and any local changes will be lost.
git reset --hard {some_revision}

create a new local branch

git branch -b {new_branch_name} {source_branch_to_start_off}

checkout all local and remote branches within the current revision of the repository.

git branch -a

delete a local branch

git branch -d {local_branch}

delete a remote branch

git push origin :{remote_branch}
# To clean up the deleted branch in other machines, run below command in other machines 
# whose local repository has the deleted remote branch.
git fetch --all --prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment