grimoire

personal wiki
git clone git://git.pyratebeard.net/grimoire.git
Log | Files | Refs

git.md (1867B)


      1 # git
      2 
      3 undo merge that hasn't been pushed
      4 ```zsh
      5 git reset --merge HEAD~1
      6 ```
      7 
      8 roll back hard
      9 ```
     10 git reset --hard <commit/tag>
     11 ```
     12 
     13 force push of a previous commit
     14 ```
     15 git push -f origin <commit_id>:<branch>
     16 ```
     17 
     18 delete remote branch
     19 ```
     20 git push --delete origin <branch>
     21 ```
     22 
     23 reset local branch after a forced-update (above)
     24 ```
     25 git fetch
     26 git reset origin/<branch> --hard
     27 ```
     28 
     29 renaming branch and updating remote
     30 ```
     31 git branch -m old-name new-name
     32 git push origin --set-upstream new-name
     33 git push origin :old-name
     34 ```
     35 
     36 set username for [single repo][]
     37 ```
     38 git config user.username 'name'
     39 ```
     40 
     41 set signing key for local repo
     42 ```
     43 git config user.signingkey <id>
     44 ```
     45 
     46 [signing][] commits
     47 ```
     48 git commit -S -m 'msg'
     49 ```
     50 
     51 compare diff between two commits
     52 ```
     53 git diff <commit>...<commit>
     54 ```
     55 
     56 stash
     57 ```
     58 git stash
     59 git stash show
     60 ```
     61 
     62 unstash
     63 ```
     64 git stash pop
     65 ```
     66 
     67 add remote origin
     68 ```
     69 git remote add origin git@gitserver/path/to/repo
     70 ```
     71 
     72 add multiple push repos
     73 ```
     74 git remote set-url --add --push origin git@gitserver/original/repo
     75 git remote set-url --add --push origin https://gitserver/another/repo
     76 ```
     77 
     78 archive branch
     79 ```
     80 git archive --format zip --outpu /path/to/output.zip <branch>
     81 ```
     82 
     83 ## using `hub`
     84 ### pull requests
     85 ```
     86 hub pr list
     87 hub pr checkout <num>
     88 ```
     89 
     90 ## helpful links
     91 
     92 [making a pull request][]
     93 
     94 [branching and rebasing][]
     95 
     96 [branching model][]
     97   
     98 [merging and rebasing][]
     99 
    100 [making a pull request]: https://www.atlassian.com/git/tutorials/making-a-pull-request
    101 [branching and rebasing]: https://git-scm.com/book/en/v2/Git-Branching-Rebasing
    102 [branching model]: https://nvie.com/posts/a-successful-git-branching-model/
    103 [single repo]: https://help.github.com/articles/setting-your-username-in-git/
    104 [merging and rebasing]: https://www.atlassian.com/git/tutorials/merging-vs-rebasing
    105 [signing]: https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work