Skip to content

Instantly share code, notes, and snippets.

@andyfoster
Forked from akras14/Getting-Cheat-Sheet.md
Created December 14, 2016 19:39
Show Gist options
  • Save andyfoster/0eaaadc9f81c3962c389c37da6f42c17 to your computer and use it in GitHub Desktop.
Save andyfoster/0eaaadc9f81c3962c389c37da6f42c17 to your computer and use it in GitHub Desktop.

Revisions

  1. @akras14 akras14 revised this gist Sep 23, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Getting-Cheat-Sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Git Cheat Sheet

    Visit [my blog](http://www.alexkras.com/) or [connect with me one Twitter](https://twitter.com/akras14)
    Visit [my blog](http://www.alexkras.com/) or [connect with me on Twitter](https://twitter.com/akras14)

    ## Commands
    ### Getting Started
    @@ -38,7 +38,7 @@ git merge branchname

    # Merge branch without fast forwarding. This is what pull requests do.
    # It helps to preserve history of the changes as relavant to that branch
    # It's an advance feature, but try it out with GUI to see the difference
    # It's an advanced feature, but try it out with GUI to see the difference
    # between the regular merge and merge --no-ff
    git merge --no--ff branchname

  2. @akras14 akras14 revised this gist Sep 13, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions Getting-Cheat-Sheet.md
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ git checkout -b new-branch-name
    # Merge branch-name into the current branch
    git merge branchname

    # Merga branch without fast forwarding. This is what pull requests do.
    # Merge branch without fast forwarding. This is what pull requests do.
    # It helps to preserve history of the changes as relavant to that branch
    # It's an advance feature, but try it out with GUI to see the difference
    # between the regular merge and merge --no-ff
    @@ -76,7 +76,7 @@ git status -s
    # Add modified file to be commited(aka stage the file)
    git add filename

    # Add all modifeid files to be commited(aka stage all files)
    # Add all modified files to be commited(aka stage all files)
    git add .

    # Add only text files, etc.
    @@ -115,17 +115,17 @@ git reset <commit-hash>
    # Save current changes, without having to commit them to repo
    git stash

    # And lated return those changes
    # And later return those changes
    git stash pop

    # Return file to it's previous version, if it haven't been stage yet.
    # Return file to it's previous version, if it hasn’t been staged yet.
    # Otherwise use git reset filename or git reset --hard filename
    git checkout filename
    ```

    **Comparing changes**
    ``` bash
    # See current changes, that have not been stage yet.
    # See current changes, that have not been staged yet.
    # Good thing to check before running git add
    git diff

  3. @akras14 akras14 revised this gist May 1, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Getting-Cheat-Sheet.md
    Original file line number Diff line number Diff line change
    @@ -63,6 +63,9 @@ git log --pretty=format:"%h %s" --graph
    # See what you worked on in the past week
    git log --author='Alex' --after={1.week.ago} --pretty=oneline --abbrev-commit

    # See only changes made on this branch (assuming it was branched form master branch)
    git log --no-merges master..

    # See status of your current git branch.
    # Often will have advice on command that you need to run
    git status
  4. @akras14 akras14 revised this gist Apr 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Getting-Cheat-Sheet.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ git branch
    git checkout branchname

    # Checkout current branch into a new branch, named new-branch-name
    git chekcout -b new-branch-name
    git checkout -b new-branch-name

    # Merge branch-name into the current branch
    git merge branchname
  5. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Getting-Cheat-Sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Git Cheat Sheet

    Visit [my blog](http://www.alexkras.com/) or [follow me one Twitter](https://twitter.com/akras14)
    Visit [my blog](http://www.alexkras.com/) or [connect with me one Twitter](https://twitter.com/akras14)

    ## Commands
    ### Getting Started
  6. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Getting-Cheat-Sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Git Cheat Sheet

    Visit [my blog](http://www.alexkras.com/), or [follow me one Twitter](https://twitter.com/akras14)
    Visit [my blog](http://www.alexkras.com/) or [follow me one Twitter](https://twitter.com/akras14)

    ## Commands
    ### Getting Started
  7. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Getting-Cheat-Sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Git CheatSheet
    # Git Cheat Sheet

    Visit [my blog](http://www.alexkras.com/), or [follow me one Twitter](https://twitter.com/akras14)

  8. @akras14 akras14 renamed this gist Apr 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Git CheatSheet

    Visit [my blog](http://www.alexkras.com/), or [follow me one Twitter](https://twitter.com/akras14)

    ## Commands
    ### Getting Started

  10. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ git chekcout -b new-branch-name
    git merge branchname

    # Merga branch without fast forwarding. This is what pull requests do.
    # it helps to preserve history of the changes as relavant to that branch
    # It helps to preserve history of the changes as relavant to that branch
    # It's an advance feature, but try it out with GUI to see the difference
    # between the regular merge and merge --no-ff
    git merge --no--ff branchname
  11. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,13 @@ git checkout branchname
    git chekcout -b new-branch-name

    # Merge branch-name into the current branch
    git merge branchname
    git merge branchname

    # Merga branch without fast forwarding. This is what pull requests do.
    # it helps to preserve history of the changes as relavant to that branch
    # It's an advance feature, but try it out with GUI to see the difference
    # between the regular merge and merge --no-ff
    git merge --no--ff branchname

    # Soft branch delete, will complain if the branch is not merged
    git branch -d branchname
  12. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -52,6 +52,9 @@ git log
    # Just google it :)
    git log --pretty=format:"%h %s" --graph

    # See what you worked on in the past week
    git log --author='Alex' --after={1.week.ago} --pretty=oneline --abbrev-commit

    # See status of your current git branch.
    # Often will have advice on command that you need to run
    git status
  13. @akras14 akras14 revised this gist Apr 16, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -132,6 +132,9 @@ git difftool -d master..

    # See only the file names that has changed in current branch
    git diff --no-commit-id --name-only --no-merges origin/master...

    # Similar to above, but see statistics on what files have changed and how
    git diff --stat #Your diff condition
    ```

    ### Working with Remote Branch
  14. @akras14 akras14 revised this gist Apr 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #Getting Started with Git
    # Git CheatSheet

    ## Commands
    ### Getting Started
  15. @akras14 akras14 revised this gist Apr 2, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -127,7 +127,11 @@ git diff branch-name
    git difftool -d

    # See only changes made in the current branch (compared to master branch)
    # Helpful when working on a stand alone branch for a while
    git difftool -d master..

    # See only the file names that has changed in current branch
    git diff --no-commit-id --name-only --no-merges origin/master...
    ```

    ### Working with Remote Branch
  16. @akras14 akras14 revised this gist Mar 20, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -126,8 +126,8 @@ git diff branch-name
    # each file one at a time.
    git difftool -d

    # See only changes made in the current branch
    git difftool -d `git merge-base master HEAD`
    # See only changes made in the current branch (compared to master branch)
    git difftool -d master..
    ```

    ### Working with Remote Branch
  17. @akras14 akras14 revised this gist Mar 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -126,7 +126,7 @@ git diff branch-name
    # each file one at a time.
    git difftool -d

    # See only changes made in current branch
    # See only changes made in the current branch
    git difftool -d `git merge-base master HEAD`
    ```

  18. @akras14 akras14 revised this gist Mar 20, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -127,9 +127,7 @@ git diff branch-name
    git difftool -d

    # See only changes made in current branch
    git merge-base master <some-branch>
    # ^ this command will return a common <common-sha>
    git difftool -d <common-sha>
    git difftool -d `git merge-base master HEAD`
    ```

    ### Working with Remote Branch
  19. @akras14 akras14 revised this gist Mar 20, 2015. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -125,6 +125,11 @@ git diff branch-name
    # -d tells it to open it in a directory mode, instead of having to open
    # each file one at a time.
    git difftool -d

    # See only changes made in current branch
    git merge-base master <some-branch>
    # ^ this command will return a common <common-sha>
    git difftool -d <common-sha>
    ```

    ### Working with Remote Branch
  20. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 16 additions and 8 deletions.
    24 changes: 16 additions & 8 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -48,10 +48,12 @@ git branch -D branchname
    # See all commits
    git log

    # Pretty commit view, you can customize it as much as you want. Just google it.
    # Pretty commit view, you can customize it as much as you want.
    # Just google it :)
    git log --pretty=format:"%h %s" --graph

    # See status of your current git branch. Often will have advice on command that you need to run
    # See status of your current git branch.
    # Often will have advice on command that you need to run
    git status

    # Short view of status. Helpful for seeing things at a glance
    @@ -69,15 +71,18 @@ git add '*.txt'
    # Tell git not to track file anymore
    git rm filename

    # Record changes to git. Default editor will open for a commit message. (Visible via git log)
    # Record changes to git. Default editor will open for a commit message.
    # (Visible via git log)
    # Once files are commited, they are history.
    git commit

    # A short hand for commiting files and writing a commit message via one command
    git commit -m 'Some commit message'

    # Changing the history :) If you want to change your previous commit, you can, if you haven't pushed it yet to a remote repo
    # Simply make new changes, add them via git add, and run the following command. Past commit will be ammended.
    # Changing the history :) If you want to change your previous commit,
    # you can, if you haven't pushed it yet to a remote repo
    # Simply make new changes, add them via git add, and run the following command.
    # Past commit will be ammended.
    git commit --amend
    ```

    @@ -124,7 +129,8 @@ git difftool -d

    ### Working with Remote Branch
    ```bash
    # See list of remote repos available. If you did git clone, you'll have at least one named "origin"
    # See list of remote repos available. If you did git clone,
    # you'll have at least one named "origin"
    git remote

    # Detailed view of remote repos, with their git urls
    @@ -133,7 +139,8 @@ git remote -v
    # Add a new remote. I.e. origin if it is not set
    git remote add origin <https://some-git-remote-url>

    # Push current branch to remote branch (usually with the same name) called upstream branch
    # Push current branch to remote branch (usually with the same name)
    # called upstream branch
    git push

    # If a remote branch is not set up as an upstream, you can make it so
    @@ -143,7 +150,8 @@ git push -u origin master
    # Otherwise you can manually specify remote and branch to use every time
    git push origin branchname

    # Just like pushing, you can get the latest updates from remote. By defaul Git will try to pull from "origin" and upstream branch
    # Just like pushing, you can get the latest updates from remote.
    # By defaul Git will try to pull from "origin" and upstream branch
    git pull

    # Or you can tell git to pull a specific branch
  21. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 10 additions and 11 deletions.
    21 changes: 10 additions & 11 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -165,16 +165,15 @@ git branch -a
    ### Reference
    - Try Github - https://try.github.io
    - lernGitBranching http://pcottle.github.io/learnGitBranching/?NODEMO
    Pro Git http://git-scm.com/book
    - Pro Git - Free Book - http://git-scm.com/book

    ### Viewing History
    Source Tree
    Command Line Setup
    https://answers.atlassian.com/questions/151279/sourcetree-command-line-option
    tig
    brew install tig
    gitk
    - Source Tree - http://www.sourcetreeapp.com/
    - tig - `sudo apt-get install tig` or `brew install tig` etc
    - gitk - `sudo apt-get install gitk`

    ### Merge/Diff Tools
    Meld - `brew install meld`
    Open Diff
    p4v Merge - http://git-scm.com/book/en/Customizing-Git-Git-Configuration#External-Merge-and-Diff-Tools
    InteliJ
    - Meld - `sudo apt-get install meld` or `brew install meld`
    - Open Diff
    - p4v Merge - http://git-scm.com/book/en/Customizing-Git-Git-Configuration#External-Merge-and-Diff-Tools
    - Webstorm
  22. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -163,8 +163,8 @@ git branch -a
    ```
    ## Resources
    ### Reference
    Try Github
    lernGitBranching http://pcottle.github.io/learnGitBranching/?NODEMO
    - Try Github - https://try.github.io
    - lernGitBranching http://pcottle.github.io/learnGitBranching/?NODEMO
    Pro Git http://git-scm.com/book
    ### Viewing History
    Source Tree
  23. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -106,11 +106,20 @@ git checkout filename

    **Comparing changes**
    ``` bash
    # See current changes, that have not been stage yet.
    # Good thing to check before running git add
    git diff

    # See current changes, that have not been commited yet (including staged changes)
    git diff HEAD
    git diff branch name

    # Compare current branch to some other branch
    git diff branch-name

    # Same as diff, but opens changes via difftool that you have configured
    # -d tells it to open it in a directory mode, instead of having to open
    # each file one at a time.
    git difftool -d
    git tag
    ```

    ### Working with Remote Branch
  24. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -104,7 +104,8 @@ git stash pop
    git checkout filename
    ```

    ```
    **Comparing changes**
    ``` bash
    git diff
    git diff HEAD
    git diff branch name
  25. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 34 additions and 7 deletions.
    41 changes: 34 additions & 7 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -113,17 +113,44 @@ git tag
    ```

    ### Working with Remote Branch
    ```bash
    # See list of remote repos available. If you did git clone, you'll have at least one named "origin"
    git remote

    # Detailed view of remote repos, with their git urls
    git remote -v

    # Add a new remote. I.e. origin if it is not set
    git remote add origin <https://some-git-remote-url>

    # Push current branch to remote branch (usually with the same name) called upstream branch
    git push
    git push
    git push -u origin master #The -u tells Git to remember the parameters

    # If a remote branch is not set up as an upstream, you can make it so
    # The -u tells Git to remember the parameters
    git push -u origin master

    # Otherwise you can manually specify remote and branch to use every time
    git push origin branchname

    # Just like pushing, you can get the latest updates from remote. By defaul Git will try to pull from "origin" and upstream branch
    git pull

    # Or you can tell git to pull a specific branch
    git pull origin branchname
    git remote
    git remote -v
    git remote add origin https://gitremote
    git fetch
    git fetch

    # Git pull, is actually a short hand for two command.
    # Telling git to first fetch changes from a remote branch
    # And then to merge them into current branch
    git fetch && git merge origin/remote-branch-name

    # If you want to update history of remote branches, you can fetch and purge
    git fetch -p

    # To see the list of remote branches
    # -a stands for all
    git branch -a
    ```
    ## Resources
    ### Reference
    Try Github
  26. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 14 additions and 3 deletions.
    17 changes: 14 additions & 3 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -83,14 +83,25 @@ git commit --amend

    **Advanced**
    ```bash
    # Unstage pending changes, the changes will still remain on file system
    git reset
    git reset

    # Unstage pending changes, and reset files to pre-commit state. If
    git reset --hard HEAD

    # Go back to some time in history, on the current branch
    git reset tag
    git reset <commit-hash>

    # Save current changes, without having to commit them to repo
    git stash
    git stash

    # And lated return those changes
    git stash pop
    git checkout filename #Goes back to the way it was

    # Return file to it's previous version, if it haven't been stage yet.
    # Otherwise use git reset filename or git reset --hard filename
    git checkout filename
    ```

    ```
  27. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ git branch -D branchname
    #### Updating Current Branch

    **Standard Flow**
    ```
    ```bash
    # See all commits
    git log

    @@ -57,19 +57,27 @@ git status
    # Short view of status. Helpful for seeing things at a glance
    git status -s

    # Add modified file to be commited
    # Add modified file to be commited(aka stage the file)
    git add filename

    # Add all modifeid files to be commited
    # Add all modifeid files to be commited(aka stage all files)
    git add .

    # Add only text files, etc.
    git add '*.txt'
    git rm

    # Tell git not to track file anymore
    git rm filename
    git commit
    git commit
    git commit -m

    # Record changes to git. Default editor will open for a commit message. (Visible via git log)
    # Once files are commited, they are history.
    git commit

    # A short hand for commiting files and writing a commit message via one command
    git commit -m 'Some commit message'

    # Changing the history :) If you want to change your previous commit, you can, if you haven't pushed it yet to a remote repo
    # Simply make new changes, add them via git add, and run the following command. Past commit will be ammended.
    git commit --amend
    ```

  28. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 14 additions and 4 deletions.
    18 changes: 14 additions & 4 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -45,15 +45,25 @@ git branch -D branchname

    **Standard Flow**
    ```
    # See all commits
    git log
    git log
    # Pretty commit view, you can customize it as much as you want. Just google it.
    git log --pretty=format:"%h %s" --graph
    # See status of your current git branch. Often will have advice on command that you need to run
    git status
    git status
    # Short view of status. Helpful for seeing things at a glance
    git status -s
    git add
    # Add modified file to be commited
    git add filename
    # Add all modifeid files to be commited
    git add .
    # Add only text files, etc.
    git add '*.txt'
    git rm
    git rm filename
    @@ -63,7 +73,7 @@ git commit -m
    git commit --amend
    ```

    Advanced
    **Advanced**
    ```bash
    git reset
    git reset
  29. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -41,9 +41,9 @@ git branch -d branchname
    git branch -D branchname
    ```

    Updating Current Branch
    #### Updating Current Branch

    Standard Flow
    **Standard Flow**
    ```
    git log
    git log
  30. @akras14 akras14 revised this gist Feb 14, 2015. 1 changed file with 15 additions and 3 deletions.
    18 changes: 15 additions & 3 deletions Getting-Started-With-Git.md
    Original file line number Diff line number Diff line change
    @@ -21,14 +21,26 @@ git config --global diff.tool meld
    ```
    ### Working with Local Branch
    #### Branching
    ```
    ```bash
    # See the list of all local branches
    git branch

    # Switch to existing local branch
    git checkout branchname
    git chekcout -b new-branch-name # Checkout current branch into a new branch, named new-branch-name
    git merge branchname # Merge branch-name into the current branch

    # Checkout current branch into a new branch, named new-branch-name
    git chekcout -b new-branch-name

    # Merge branch-name into the current branch
    git merge branchname

    # Soft branch delete, will complain if the branch is not merged
    git branch -d branchname

    # Hard branch delete, will not complain about nothing. Like rm -rf in bash
    git branch -D branchname
    ```

    Updating Current Branch

    Standard Flow