Skip to content

Instantly share code, notes, and snippets.

@dsvanidze
Forked from hofmannsven/README.md
Created June 23, 2019 05:40
Show Gist options
  • Save dsvanidze/aaed9be7ca68d18ebd9ece6b29f04750 to your computer and use it in GitHub Desktop.
Save dsvanidze/aaed9be7ca68d18ebd9ece6b29f04750 to your computer and use it in GitHub Desktop.

Revisions

  1. @hofmannsven hofmannsven revised this gist Mar 21, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Using Git
    # Git

    ## Global Settings
    - Related Setup: https://gist.github.com/hofmannsven/6814278
  2. @hofmannsven hofmannsven revised this gist Mar 21, 2019. 1 changed file with 20 additions and 78 deletions.
    98 changes: 20 additions & 78 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,20 @@
    Using Git
    ===============

    Global Settings
    -----------
    # Using Git

    ## Global Settings
    - Related Setup: https://gist.github.com/hofmannsven/6814278
    - Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
    - Interactive Beginners Tutorial: http://try.github.io/
    - Git Cheatsheet by GitHub: https://services.github.com/on-demand/downloads/github-git-cheat-sheet/


    Reminder
    -----------

    ## Reminder
    Press `minus + shift + s` and `return` to chop/fold long lines!

    Show folder content: `ls -la`


    Notes
    -----------

    ## Notes
    Do not put (external) dependencies in version control!


    Setup
    -----------

    ## Setup
    See where Git is located:
    `which git`

    @@ -36,17 +24,10 @@ Get the version of Git:
    Create an alias (shortcut) for `git status`:
    `git config --global alias.st status`


    Help
    -----------

    Help:
    `git help`


    General
    -----------

    ## General
    Initialize Git:
    `git init`

    @@ -83,10 +64,7 @@ Undo modifications (restore files from latest commited version):
    Restore file from a custom commit (in current branch):
    `git checkout 6eb715d -- index.html`


    Reset
    -----------

    ## Reset
    Go back to commit:
    `git revert 073791e7dd71b90daa853b2c5acc2c925f02dbc6`

    @@ -104,9 +82,7 @@ Hard reset (move HEAD and change staging dir and working dir to match repo):
    Hard reset of a single file (`@` is short for `HEAD`):
    `git checkout @ -- index.html`

    Update & Delete
    -----------

    ## Update & Delete
    Test-Delete untracked files:
    `git clean -n`

    @@ -119,10 +95,7 @@ Unstage (undo adds):
    Update most recent commit (also update the commit message):
    `git commit --amend -m "New Message"`


    Branch
    -----------

    ## Branch
    Show branches:
    `git branch`

    @@ -149,10 +122,7 @@ Delete merged branch (only possible if not HEAD):
    Delete not merged branch:
    `git branch -D branch_to_delete`


    Merge
    -----------

    ## Merge
    True merge (fast forward):
    `git merge branchname`

    @@ -189,9 +159,7 @@ Squash multiple commits into one:
    Squash-merge a feature branch (as one commit):
    `git merge --squash branchname` (commit afterwards)

    Stash
    -----------

    ## Stash
    Put in stash:
    `git stash save "Message"`

    @@ -222,10 +190,7 @@ Delete custom stash item:
    Delete complete stash:
    `git stash clear`


    Gitignore & Gitkeep
    -----------

    ## Gitignore & Gitkeep
    About: https://help.github.com/articles/ignoring-files

    Useful templates: https://github.com/github/gitignore
    @@ -236,10 +201,7 @@ Add or edit gitignore:
    Track empty dir:
    `touch dir/.gitkeep`


    Log
    -----------

    ## Log
    Show commits:
    `git log`

    @@ -283,10 +245,7 @@ Show history of commits as graph:
    Show history of commits as graph-summary:
    `git log --oneline --graph --all --decorate`


    Compare
    -----------

    ## Compare
    Compare modified files:
    `git diff`

    @@ -325,10 +284,7 @@ Useful comparings:
    Blame:
    `git blame -L10,+1 index.html`


    Releases & Version Tags
    -----------

    ## Releases & Version Tags
    Show all released versions:
    `git tag`

    @@ -344,10 +300,7 @@ Create release version with comment:
    Checkout a specific release version:
    `git checkout v1.0.0`


    Collaborate
    -----------

    ## Collaborate
    Show remote:
    `git remote`

    @@ -419,30 +372,19 @@ Delete remote branch (push nothing):
    `git push origin :branchname` or:
    `git push origin --delete branchname`


    Archive
    -----------
    ## Archive
    Create a zip-archive: `git archive --format zip --output filename.zip master`

    Export/write custom log to a file: `git log --author=sven --all > log.txt`


    Troubleshooting
    -----------

    ## Troubleshooting
    Ignore files that have already been committed to a Git repository: http://stackoverflow.com/a/1139797/1815847


    Security
    -----------

    ## Security
    Hide Git on the web via `.htaccess`: `RedirectMatch 404 /\.git`
    (more info here: http://stackoverflow.com/a/17916515/1815847)


    Large File Storage
    -----------

    ## Large File Storage
    Website: https://git-lfs.github.com/

    Install: `brew install git-lfs`
  3. @hofmannsven hofmannsven revised this gist Mar 20, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -412,6 +412,9 @@ Clone to localhost folder:
    Clone specific branch to localhost:
    `git clone -b branchname https://github.com/user/project.git`

    Clone with token authentication (in CI environment):
    `git clone https://oauth2:<token>@gitlab.com/username/repo.git`

    Delete remote branch (push nothing):
    `git push origin :branchname` or:
    `git push origin --delete branchname`
  4. @hofmannsven hofmannsven revised this gist Mar 14, 2019. No changes.
  5. @hofmannsven hofmannsven revised this gist Jan 25, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -168,6 +168,9 @@ Stop merge (in case of conflicts):
    Stop merge (in case of conflicts):
    `git reset --merge` // prior to v1.7.4

    Undo local merge that hasn't been pushed yet:
    `git reset --hard origin/master`

    Merge only one specific commit:
    `git cherry-pick 073791e7`

    @@ -183,6 +186,9 @@ Cancel rebase:
    Squash multiple commits into one:
    `git rebase -i HEAD~3` ([source](https://www.devroom.io/2011/07/05/git-squash-your-latests-commits-into-one/))

    Squash-merge a feature branch (as one commit):
    `git merge --squash branchname` (commit afterwards)

    Stash
    -----------

  6. @hofmannsven hofmannsven revised this gist Jan 21, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -101,6 +101,9 @@ Mixed reset (move HEAD and change staging to match repo; does not affect working
    Hard reset (move HEAD and change staging dir and working dir to match repo):
    `git reset --hard 073791e7dd71b90daa853b2c5acc2c925f02dbc6`

    Hard reset of a single file (`@` is short for `HEAD`):
    `git checkout @ -- index.html`

    Update & Delete
    -----------

  7. @hofmannsven hofmannsven revised this gist Jan 16, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -201,6 +201,12 @@ Use custom stash item and drop it:
    Use custom stash item and do not drop it:
    `git stash apply stash@{0}`

    Use custom stash item and index:
    `git stash apply --index`

    Create branch from stash:
    `git stash branch new_branch`

    Delete custom stash item:
    `git stash drop stash@{0}`

  8. @hofmannsven hofmannsven revised this gist Jan 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -360,7 +360,7 @@ Remove origin:
    Show remote branches:
    `git branch -r`

    Show all branches:
    Show all branches (remote and local):
    `git branch -a`

    Create and checkout branch from a remote branch:
  9. @hofmannsven hofmannsven revised this gist Oct 31, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -59,6 +59,9 @@ Get custom file ready to commit:
    Commit changes:
    `git commit -m "Message"`

    Commit changes with title and description:
    `git commit -m "Title" -m "Description..."`

    Add and commit in one step:
    `git commit -am "Message"`

  10. @hofmannsven hofmannsven revised this gist Aug 23, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -171,7 +171,7 @@ or:
    `git merge master branchname`
    (The rebase moves all of the commits in `master` onto the tip of `branchname`.)

    Abort rebase:
    Cancel rebase:
    `git rebase --abort`

    Squash multiple commits into one:
  11. @hofmannsven hofmannsven revised this gist Aug 23, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -171,6 +171,9 @@ or:
    `git merge master branchname`
    (The rebase moves all of the commits in `master` onto the tip of `branchname`.)

    Abort rebase:
    `git rebase --abort`

    Squash multiple commits into one:
    `git rebase -i HEAD~3` ([source](https://www.devroom.io/2011/07/05/git-squash-your-latests-commits-into-one/))

  12. @hofmannsven hofmannsven revised this gist Jul 3, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -357,6 +357,9 @@ Show remote branches:
    Show all branches:
    `git branch -a`

    Create and checkout branch from a remote branch:
    `git checkout -b local_branchname upstream/remote_branchname`

    Compare:
    `git diff origin/master..master`

  13. @hofmannsven hofmannsven revised this gist Jun 22, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -375,6 +375,9 @@ Pull:
    Pull specific branch:
    `git pull origin branchname`

    Fetch a pull request on GitHub by its ID and create a new branch:
    `git fetch upstream pull/ID/head:new-pr-branch`

    Clone to localhost:
    `git clone https://github.com/user/project.git` or:
    `git clone ssh://[email protected]/~/dir/.git`
  14. @hofmannsven hofmannsven revised this gist May 3, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ Global Settings
    - Related Setup: https://gist.github.com/hofmannsven/6814278
    - Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
    - Interactive Beginners Tutorial: http://try.github.io/
    - GitHub Cheatsheet: https://services.github.com/on-demand/downloads/github-git-cheat-sheet/
    - Git Cheatsheet by GitHub: https://services.github.com/on-demand/downloads/github-git-cheat-sheet/


    Reminder
  15. @hofmannsven hofmannsven revised this gist May 3, 2018. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,10 @@ Using Git
    Global Settings
    -----------

    Related Setup: https://gist.github.com/hofmannsven/6814278

    Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/

    Interactive Beginners Tutorial: http://try.github.io/
    - Related Setup: https://gist.github.com/hofmannsven/6814278
    - Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
    - Interactive Beginners Tutorial: http://try.github.io/
    - GitHub Cheatsheet: https://services.github.com/on-demand/downloads/github-git-cheat-sheet/


    Reminder
  16. @hofmannsven hofmannsven revised this gist May 3, 2018. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -111,10 +111,7 @@ Delete untracked files (not staging):
    Unstage (undo adds):
    `git reset HEAD index.html`

    Commit to most recent commit:
    `git commit --amend -m "Message"`

    Update most recent commit message:
    Update most recent commit (also update the commit message):
    `git commit --amend -m "New Message"`


  17. @hofmannsven hofmannsven revised this gist May 3, 2018. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -337,11 +337,20 @@ Show remote:
    Show remote details:
    `git remote -v`

    Add remote origin from GitHub project:
    `git remote add origin https://github.com/user/project.git`
    Add remote upstream from GitHub project:
    `git remote add upstream https://github.com/user/project.git`

    Add remote origin from existing empty project on server:
    `git remote add origin ssh://[email protected]/path/to/repository/.git`
    Add remote upstream from existing empty project on server:
    `git remote add upstream ssh://[email protected]/path/to/repository/.git`

    Fetch:
    `git fetch upstream`

    Fetch a custom branch:
    `git fetch upstream branchname:local_branchname`

    Merge fetched commits:
    `git merge upstream/master`

    Remove origin:
    `git remote rm origin`
    @@ -362,23 +371,14 @@ Push:
    `git push origin master`

    Force-Push:
    `git push origin master --force`

    Fetch:
    `git fetch origin`

    Fetch a custom branch:
    `git fetch origin branchname:local_branchname`
    `git push origin master --force

    Pull:
    `git pull`

    Pull specific branch:
    `git pull origin branchname`

    Merge fetched commits:
    `git merge origin/master`

    Clone to localhost:
    `git clone https://github.com/user/project.git` or:
    `git clone ssh://[email protected]/~/dir/.git`
  18. @hofmannsven hofmannsven revised this gist Mar 26, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -175,6 +175,8 @@ or:
    `git merge master branchname`
    (The rebase moves all of the commits in `master` onto the tip of `branchname`.)

    Squash multiple commits into one:
    `git rebase -i HEAD~3` ([source](https://www.devroom.io/2011/07/05/git-squash-your-latests-commits-into-one/))

    Stash
    -----------
  19. @hofmannsven hofmannsven revised this gist Mar 26, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -356,9 +356,12 @@ Compare:
    Push (set default with `-u`):
    `git push -u origin master`

    Push to default:
    Push:
    `git push origin master`

    Force-Push:
    `git push origin master --force`

    Fetch:
    `git fetch origin`

  20. @hofmannsven hofmannsven revised this gist Mar 26, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -169,6 +169,13 @@ Stop merge (in case of conflicts):
    Merge only one specific commit:
    `git cherry-pick 073791e7`

    Rebase:
    `git checkout branchname` » `git rebase master`
    or:
    `git merge master branchname`
    (The rebase moves all of the commits in `master` onto the tip of `branchname`.)


    Stash
    -----------

  21. @hofmannsven hofmannsven revised this gist Apr 4, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -157,7 +157,7 @@ True merge (fast forward):
    Merge to master (only if fast forward):
    `git merge --ff-only branchname`

    Merge to master (forc a new commit):
    Merge to master (force a new commit):
    `git merge --no-ff branchname`

    Stop merge (in case of conflicts):
  22. @hofmannsven hofmannsven revised this gist Apr 4, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -355,6 +355,9 @@ Push to default:
    Fetch:
    `git fetch origin`

    Fetch a custom branch:
    `git fetch origin branchname:local_branchname`

    Pull:
    `git pull`

  23. @hofmannsven hofmannsven revised this gist Feb 25, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -166,6 +166,8 @@ Stop merge (in case of conflicts):
    Stop merge (in case of conflicts):
    `git reset --merge` // prior to v1.7.4

    Merge only one specific commit:
    `git cherry-pick 073791e7`

    Stash
    -----------
  24. @hofmannsven hofmannsven revised this gist Oct 13, 2016. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,12 @@ Press `minus + shift + s` and `return` to chop/fold long lines!
    Show folder content: `ls -la`


    Notes
    -----------

    Do not put (external) dependencies in version control!


    Setup
    -----------

  25. @hofmannsven hofmannsven revised this gist Jun 17, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -85,6 +85,8 @@ Go back to commit:
    Soft reset (move HEAD only; neither staging nor working dir is changed):
    `git reset --soft 073791e7dd71b90daa853b2c5acc2c925f02dbc6`

    Undo latest commit: `git reset --soft HEAD~ `

    Mixed reset (move HEAD and change staging to match repo; does not affect working dir):
    `git reset --mixed 073791e7dd71b90daa853b2c5acc2c925f02dbc6`

  26. @hofmannsven hofmannsven revised this gist Jun 6, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -373,6 +373,8 @@ Archive
    -----------
    Create a zip-archive: `git archive --format zip --output filename.zip master`

    Export/write custom log to a file: `git log --author=sven --all > log.txt`


    Troubleshooting
    -----------
  27. @hofmannsven hofmannsven revised this gist Oct 19, 2015. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -384,4 +384,14 @@ Security
    -----------

    Hide Git on the web via `.htaccess`: `RedirectMatch 404 /\.git`
    (more info here: http://stackoverflow.com/a/17916515/1815847)
    (more info here: http://stackoverflow.com/a/17916515/1815847)


    Large File Storage
    -----------

    Website: https://git-lfs.github.com/

    Install: `brew install git-lfs`

    Track `*.psd` files: `git lfs track "*.psd"` (init, add, commit and push as written above)
  28. @hofmannsven hofmannsven revised this gist Jul 29, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -383,5 +383,5 @@ Ignore files that have already been committed to a Git repository: http://stacko
    Security
    -----------

    Prevent access to `.git` folders via `.htaccess`: `RedirectMatch 404 /\.git`
    Hide Git on the web via `.htaccess`: `RedirectMatch 404 /\.git`
    (more info here: http://stackoverflow.com/a/17916515/1815847)
  29. @hofmannsven hofmannsven revised this gist Jul 29, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -384,4 +384,4 @@ Security
    -----------

    Prevent access to `.git` folders via `.htaccess`: `RedirectMatch 404 /\.git`
    (more in here: http://stackoverflow.com/a/17916515/1815847)
    (more info here: http://stackoverflow.com/a/17916515/1815847)
  30. @hofmannsven hofmannsven revised this gist Jul 29, 2015. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -377,4 +377,11 @@ Create a zip-archive: `git archive --format zip --output filename.zip master`
    Troubleshooting
    -----------

    Ignore files that have already been committed to a Git repository: http://stackoverflow.com/a/1139797/1815847
    Ignore files that have already been committed to a Git repository: http://stackoverflow.com/a/1139797/1815847


    Security
    -----------

    Prevent access to `.git` folders via `.htaccess`: `RedirectMatch 404 /\.git`
    (more in here: http://stackoverflow.com/a/17916515/1815847)