Skip to content

Instantly share code, notes, and snippets.

@ryuichi24
Last active July 25, 2021 20:13
Show Gist options
  • Select an option

  • Save ryuichi24/c246d93efb26a945643b8175da560559 to your computer and use it in GitHub Desktop.

Select an option

Save ryuichi24/c246d93efb26a945643b8175da560559 to your computer and use it in GitHub Desktop.

Revisions

  1. ryuichi24 revised this gist Jul 25, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,9 @@
    ## 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>`

  2. ryuichi24 revised this gist Jul 20, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,9 @@
    ## 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`

  3. ryuichi24 revised this gist Jul 18, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,12 @@
    ## 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>`

    ## update local repository with remote branch references
    `git fetch`

  4. ryuichi24 revised this gist Jul 16, 2021. 1 changed file with 3 additions and 9 deletions.
    12 changes: 3 additions & 9 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -54,21 +54,15 @@
    ## delete all stashed changes
    `git stash clear`

    ## undo a git push
    `git push -f origin HEAD^:main`
    ## reset to a certain commit with soft
    `git reset --soft <commit hash>`

    ## reset to a certain commit
    ## 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>`

    ## undo last commit (preserves working tree)
    `git reset --soft HEAD~1`

    ## undo last commit (lose working tree)
    `git reset --hard HEAD^`

    ## ignore file
    `git update-index --assume-unchanged <file name>`

  5. ryuichi24 revised this gist Jul 1, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -57,6 +57,12 @@
    ## undo a git push
    `git push -f origin HEAD^:main`

    ## reset to a certain commit
    `git reset --hard <commit hash>`

    ## force push with reset local branch
    `git push --force-with-lease origin <branch name>`

    ## undo last commit (preserves working tree)
    `git reset --soft HEAD~1`

  6. ryuichi24 revised this gist Jun 22, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -58,7 +58,7 @@
    `git push -f origin HEAD^:main`

    ## undo last commit (preserves working tree)
    `git reset --soft HEAD`
    `git reset --soft HEAD~1`

    ## undo last commit (lose working tree)
    `git reset --hard HEAD^`
  7. ryuichi24 revised this gist Jun 17, 2021. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -64,4 +64,7 @@
    `git reset --hard HEAD^`

    ## ignore file
    `git update-index --assume-unchanged <file name>`
    `git update-index --assume-unchanged <file name>`

    ## undo ignore file
    `git update-index --no-assume-unchanged <file>`
  8. ryuichi24 revised this gist Jun 17, 2021. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -61,4 +61,7 @@
    `git reset --soft HEAD`

    ## undo last commit (lose working tree)
    `git reset --hard HEAD^`
    `git reset --hard HEAD^`

    ## ignore file
    `git update-index --assume-unchanged <file name>`
  9. ryuichi24 revised this gist May 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@
    `git stash clear`

    ## undo a git push
    `git push -f origin HEAD^:master`
    `git push -f origin HEAD^:main`

    ## undo last commit (preserves working tree)
    `git reset --soft HEAD`
  10. ryuichi24 revised this gist May 16, 2021. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -52,4 +52,13 @@
    `git stash drop <stash name>`

    ## delete all stashed changes
    `git stash clear`
    `git stash clear`

    ## undo a git push
    `git push -f origin HEAD^:master`

    ## undo last commit (preserves working tree)
    `git reset --soft HEAD`

    ## undo last commit (lose working tree)
    `git reset --hard HEAD^`
  11. ryuichi24 revised this gist Jan 28, 2021. 1 changed file with 22 additions and 1 deletion.
    23 changes: 22 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,25 @@
    `git fetch`

    ## restore working tree files in the current directory
    `git restore .`
    `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`
  12. ryuichi24 revised this gist Jan 24, 2021. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -28,4 +28,7 @@
    `git checkout -b <new branch name>`

    ## update local repository with remote branch references
    `git fetch`
    `git fetch`

    ## restore working tree files in the current directory
    `git restore .`
  13. ryuichi24 revised this gist Jan 22, 2021. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion git_commands.md
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,7 @@
    `git checkout <branch>`

    ## create a new branch and swich to it
    `git checkout -b <new branch name>`
    `git checkout -b <new branch name>`

    ## update local repository with remote branch references
    `git fetch`
  14. ryuichi24 created this gist Jan 20, 2021.
    28 changes: 28 additions & 0 deletions git_commands.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # 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>"`

    ## 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>`