Skip to content

Instantly share code, notes, and snippets.

@ryuichi24
Last active July 25, 2021 20:13
Show Gist options
  • Save ryuichi24/c246d93efb26a945643b8175da560559 to your computer and use it in GitHub Desktop.
Save ryuichi24/c246d93efb26a945643b8175da560559 to your computer and use it in GitHub Desktop.

Git commands

init local repository

git init

add changes to stage in the local

git add <files or directories>

add all changes in the local

git add .

commit changes to new commmit object being ready for remote repository

git commit -m "<comment>"

amend last commit message

git commit --amend -m <new message>

push the committed changes to the remote repository

git push <remote> <branch>

pull changes in the remote repository

git pull <remote> <branch>

list all branches

git branch

switch to the selected branch

git checkout <branch>

create a new branch and swich to it

git checkout -b <new branch name>

remove local branch

git branch -d <branch name>

remove remote branch

git push origin --delete <branch name>

set upstream for a local branch

git branch --set-upstream-to=origin/<remote branch> <local branch>

update local repository with remote branch references

git fetch

restore working tree files in the current directory

git restore .

save the current changes in stash

git stash || git stash save "some comment to the changes"

display all stashed changes

git stash list

display changes of selected stash

git stash show -p <stash name>

apply stashed changes but keep the stashed

git stash apply <stash name>

apply stashed changes and delete the stashed

git stash pop <stash name>

delete selected stashed changes

git stash drop <stash name>

delete all stashed changes

git stash clear

reset to a certain commit with soft

git reset --soft <commit hash>

reset to a certain commit with hard

git reset --hard <commit hash>

force push with reset local branch

git push --force-with-lease origin <branch name>

ignore file

git update-index --assume-unchanged <file name>

undo ignore file

git update-index --no-assume-unchanged <file>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment