Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active June 18, 2025 06:22

Revisions

  1. neilgee revised this gist Mar 7, 2021. No changes.
  2. neilgee revised this gist Sep 12, 2017. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -353,4 +353,15 @@ git branch -vv /* Shows which branch is the Upstream, if you need to change just

    git checkout -b newbranchname

    git pull https://github.com/username/the-repo.git theirbranchname
    git pull https://github.com/username/the-repo.git theirbranchname


    /*
    * Remove Git submodule - https://stackoverflow.com/questions/1759587/un-submodule-a-git-submodule
    */
    git rm --cached submodule_path # delete reference to submodule HEAD (no trailing slash)
    git rm .gitmodules # if you have more than one submodules,
    # you need to edit this file instead of deleting!
    rm -rf submodule_path/.git # make sure you have backup!!
    git add submodule_path # will add files instead of commit reference
    git commit -m "remove submodule"
  3. neilgee revised this gist Sep 12, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -284,6 +284,8 @@ git push --force origin master

    git rm --cached filetoremove /* Removes a file that is committed from repo but leaves it still locally - handy when you've added something that you don't want tracked */

    /* Undo last push to github - below forces commit entered in to overwrite remote - so in case below origin is local and master is remote*/
    git push -f origin last_known_good_commit:master

    /*
    * Tags
  4. neilgee revised this gist Aug 12, 2017. No changes.
  5. neilgee revised this gist Mar 9, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -282,6 +282,8 @@ git reset --hard HEAD^ /*restore prior commit */

    git push --force origin master

    git rm --cached filetoremove /* Removes a file that is committed from repo but leaves it still locally - handy when you've added something that you don't want tracked */


    /*
    * Tags
  6. neilgee revised this gist Mar 5, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -141,11 +141,11 @@ git log --grep="temp"

    git show dc094cb /* show SHA1 */

    /* Compare Commits
    /* Compare Commits */

    Branches */
    /* Branches */

    git branch /* Show local branches * is the one we are on */
    git branch /* Show local branch name - the asterisk * is the one we are on */

    git branch -r /* Shows remote branches */

  7. neilgee revised this gist Mar 2, 2017. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -312,6 +312,7 @@ git push origin :refs/tags/v1.0.0 /*push change to remote - change 'origin' to y
    git tag v1.0.0 /*create new tag - change version number to suit */
    git push origin master --tags /* assign to latest commit - change 'origin' to your remote name*/


    /*
    * Syncing a Fork
    * Have the Fork already created in Github
    @@ -332,6 +333,16 @@ git push origin master --tags /* assign to latest commit - change 'origin' to y
    /* This will result in the fork master branch being 'even' with the original master branch */


    /*
    * Creating an Upstream Branch from an already added branch
    */

    git push --set-upstream dev master /* Here the remote 'dev' branch is set as Upstream to the local 'master' branch */

    git branch -vv /* Shows which branch is the Upstream, if you need to change just use the preceeding command again */



    /*
    * Checking out a Fork with a certain pull request on a new branch
    */
  8. neilgee revised this gist Nov 4, 2016. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,14 @@ git add .
    * Commit the change to git
    */

    git commit -m "Message about the change goes here"
    git commit -m "Message about the change goes here" <filename>


    /*
    * Commit all changes to git of muliple files - no filenames needed
    */

    git commit -am "Message about the change goes here"


    /*
  9. neilgee revised this gist Sep 5, 2016. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -322,4 +322,13 @@ git push origin master --tags /* assign to latest commit - change 'origin' to y
    git rebase upstream/master /* rewrite your local master branch on top of the upstream */

    git push -f origin master /* needs -f the first time after rebase */
    /* This will result in the fork master branch being 'even' with the original master branch */
    /* This will result in the fork master branch being 'even' with the original master branch */


    /*
    * Checking out a Fork with a certain pull request on a new branch
    */

    git checkout -b newbranchname

    git pull https://github.com/username/the-repo.git theirbranchname
  10. neilgee revised this gist Sep 4, 2016. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -269,11 +269,12 @@ git checkout HEAD^ path-to-file /*if is staged and committed - restores from las

    git reset --hard HEAD^ /*restore prior commit */

    /*Keeping a Fork synced with the original repo*/
    /*Keeping the local synced with the origin after the local is reset
    * ref http://stackoverflow.com/questions/17667023/git-how-to-reset-origin-master-to-a-commit
    */

    git remote add upstream https://github.com/user/originalrepo /* From the forked repo - add the original master repo */
    git push --force origin master

    git pull upstream master /* Sync it up */

    /*
    * Tags
  11. neilgee revised this gist Aug 15, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -321,3 +321,4 @@ git push origin master --tags /* assign to latest commit - change 'origin' to y
    git rebase upstream/master /* rewrite your local master branch on top of the upstream */

    git push -f origin master /* needs -f the first time after rebase */
    /* This will result in the fork master branch being 'even' with the original master branch */
  12. neilgee revised this gist Aug 15, 2016. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -303,3 +303,21 @@ git push origin :refs/tags/v1.0.0 /*push change to remote - change 'origin' to y
    */
    git tag v1.0.0 /*create new tag - change version number to suit */
    git push origin master --tags /* assign to latest commit - change 'origin' to your remote name*/

    /*
    * Syncing a Fork
    * Have the Fork already created in Github
    * http://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository
    */

    git clone git@github.com:me/myfork.git myfork /* make a local copy of the fork */
    /* cd into the repo*/
    git remote add upstream https://github.com/theotherguy/theoriginal.git /* make an upstream remote repo */
    git remote -v /* check all the repos */

    git fetch upstream /* get the original repo */
    git checkout master /* ensure you in your local master branch */

    git rebase upstream/master /* rewrite your local master branch on top of the upstream */

    git push -f origin master /* needs -f the first time after rebase */
  13. neilgee revised this gist Apr 1, 2016. 1 changed file with 16 additions and 4 deletions.
    20 changes: 16 additions & 4 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -275,7 +275,10 @@ git remote add upstream https://github.com/user/originalrepo /* From the forked

    git pull upstream master /* Sync it up */

    /*Tags*/
    /*
    * Tags
    * Adding a Tag
    */

    git tag -a v1.0.0 -m "add message here" /*tagging a commit with a version number*/

    @@ -285,9 +288,18 @@ git push --tags /* pushes tag info to master remote */

    git checkout f1f4a3d /*checking out a commit - see the commit SHAS by git log */

    /*Changing Tag to different commit */
    /*
    * Changing Tag to different commit
    */

    /*
    * Deleting the tag
    */
    git tag -d v1.0.0 /*change version number to suit - we are deleting it here*/
    git push origin :refs/tags/v1.0.0 /*push change to remote*/
    git push origin :refs/tags/v1.0.0 /*push change to remote - change 'origin' to your remote name*/

    /*
    * Adding it again - but this time it would be to the latest commit
    */
    git tag v1.0.0 /*create new tag - change version number to suit */
    git push origin master --tags /* assign to latest commit */
    git push origin master --tags /* assign to latest commit - change 'origin' to your remote name*/
  14. neilgee revised this gist Apr 1, 2016. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -196,10 +196,13 @@ git stash clear /* removes all stash */
    git stash drop stash@{0}


    /* Remotes
    You can push and fetch to the remote server, merge any differences - then push any new to the remote - 3 branches work remote server branch, local origin master and local master
    Create a repo in GitHub, then add that remote to your local repo */
    /*
    * Remotes
    * You can push and fetch to the remote server, merge any differences - then push any new to the remote - 3 branches work remote server branch, local origin master and local master
    *
    * Create a repo in GitHub, then add that remote to your local repo
    * You will need to add a SSH key from your local machine and store it in GitHub - ref: https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
    */

    git remote add origin https://github.com/neilgee/genesischild.git /* origin can be named whatever followed by the remote */

  15. neilgee revised this gist Mar 25, 2016. 1 changed file with 44 additions and 14 deletions.
    58 changes: 44 additions & 14 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,70 @@
    /* Set up Git Configuration */
    /*
    * Set up your Git configuration
    */

    git config --global user.email "[email protected]"

    git config --global user.name "Your Name"

    git config --global core.editor "vi"
    git config --global core.editor "nano"

    git config --global color.ui true

    /* See Git configuration */

    /*
    *See Git configuration
    */

    git config --list

    /* To initialise a local repository */

    /*
    * To initialise a local repository
    */

    git init

    /* Add a file to the repo */

    git add
    /*
    * Add a file to the repo
    */

    /* commit the change to git */
    git add <filename>

    git commit -m "Message goes here"

    /* see the commits */
    /*
    * Add all the files to the repo
    */

    git log
    git add .


    /*
    * Commit the change to git
    */

    /* Git has a 3 Tier Architecture: Working - Staging - Repo
    git commit -m "Message about the change goes here"


    /*
    * See the commits in a historical linear fashion
    */

    git log

    Changes to files are put in a Checksum SHA-1 hash 40digit value containing parent hash, author and message.

    HEAD is the latest commit of the checked out branch */
    /*
    * Git has a 3 Tier Architecture: Working - Staging - Repo
    *
    * Changes to files are put in a Checksum SHA-1 hash 40digit value containing parent hash, author and message.
    *
    * HEAD is the latest commit of the checked out branch
    */


    /* Basic Commands */
    /*
    * Basic Commands
    */

    git status /* the command 'git status' tells which files are not added or committed from Working to Staging to Repository */

  16. neilgee revised this gist Jan 16, 2016. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -250,4 +250,11 @@ git push --tags /* pushes tag info to master remote */

    /*You can checkout a commit and add a tag to that commit by checking out its SHA */

    git checkout f1f4a3d /*checking out a commit - see the commit SHAS by git log */
    git checkout f1f4a3d /*checking out a commit - see the commit SHAS by git log */

    /*Changing Tag to different commit */

    git tag -d v1.0.0 /*change version number to suit - we are deleting it here*/
    git push origin :refs/tags/v1.0.0 /*push change to remote*/
    git tag v1.0.0 /*create new tag - change version number to suit */
    git push origin master --tags /* assign to latest commit */
  17. neilgee revised this gist Oct 11, 2015. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -240,4 +240,14 @@ git reset --hard HEAD^ /*restore prior commit */

    git remote add upstream https://github.com/user/originalrepo /* From the forked repo - add the original master repo */

    git pull upstream master /* Sync it up */
    git pull upstream master /* Sync it up */

    /*Tags*/

    git tag -a v1.0.0 -m "add message here" /*tagging a commit with a version number*/

    git push --tags /* pushes tag info to master remote */

    /*You can checkout a commit and add a tag to that commit by checking out its SHA */

    git checkout f1f4a3d /*checking out a commit - see the commit SHAS by git log */
  18. neilgee revised this gist Oct 9, 2015. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -234,4 +234,10 @@ git reset HEAD path-to-file /*if it is staged - restores a file from last commit

    git checkout HEAD^ path-to-file /*if is staged and committed - restores from last commit */

    git reset --hard HEAD^ /*restore prior commit */
    git reset --hard HEAD^ /*restore prior commit */

    /*Keeping a Fork synced with the original repo*/

    git remote add upstream https://github.com/user/originalrepo /* From the forked repo - add the original master repo */

    git pull upstream master /* Sync it up */
  19. neilgee revised this gist Oct 5, 2015. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -224,3 +224,14 @@ git checkout -b nontracking origin/nontracking
    /* Remove remote branch */

    git push origin --delete branch


    /*Undoing*/

    git checkout path-to-file /*restores a file before it is staged */

    git reset HEAD path-to-file /*if it is staged - restores a file from last commit and then git checkout path-to-file */

    git checkout HEAD^ path-to-file /*if is staged and committed - restores from last commit */

    git reset --hard HEAD^ /*restore prior commit */
  20. neilgee revised this gist Oct 5, 2015. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -120,6 +120,8 @@ git checkout newbranch /* switch to new branch */

    git checkout -b oldbranch /* creates and switches to new branch */

    git push origin newbranch /* Push new branch to remote */


    /* Diff in Branches */

    @@ -163,6 +165,7 @@ git stash clear /* removes all stash */

    git stash drop stash@{0}


    /* Remotes
    You can push and fetch to the remote server, merge any differences - then push any new to the remote - 3 branches work remote server branch, local origin master and local master
    @@ -190,6 +193,8 @@ git clone https://github.com/neilgee/genesischild.git nameoffolder

    git push

    git push origin newbranch /* Push a branch to a remote */

    /* Fetch changes from a cloned Repo */

    git fetch origin /* Pulls down latest committs from remote origin/master not origin, also pull down any branches pushed to Repo
  21. neilgee revised this gist Apr 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -139,7 +139,7 @@ git branch -d nameofbranch

    /* Merge Branch */

    git merge branchname /* be on the receiver branch */
    git merge branchname /* be on the receiver branch to merge the other branch */

    /* Merge Conflicts between the same file on 2 branches are marked in HEAD and other branch */

  22. neilgee revised this gist Apr 6, 2015. 1 changed file with 15 additions and 12 deletions.
    27 changes: 15 additions & 12 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -12,11 +12,11 @@ git config --global color.ui true

    git config --list

    /* to initialise a local repository */
    /* To initialise a local repository */

    git init

    /* adds a file to the repo */
    /* Add a file to the repo */

    git add

    @@ -28,7 +28,7 @@ git commit -m "Message goes here"

    git log

    /* Git has a 3 Tier Architecture: Working - Staging Index - Respository
    /* Git has a 3 Tier Architecture: Working - Staging - Repo
    Changes to files are put in a Checksum SHA-1 hash 40digit value containing parent hash, author and message.
    @@ -38,13 +38,14 @@ HEAD is the latest commit of the checked out branch */

    git status /* the command 'git status' tells which files are not added or committed from Working to Staging to Repository */

    git commit -m "" /* Commits and changes to all files that are in Staging Tier into Repository */
    git commit -m "" /* Commits and changes to all files that are in Staging into Repo */

    git diff /* show changes between Working and Repository, no file supplied shows all files */
    git diff /* show changes between Working and Local Repo, no file supplied shows all files */

    git diff --staged /* shows changes between Staged and Respository */
    git diff --staged /* shows changes between Staged and Local Repo */

    git rm file.txt /* will remove file from working then git commit -m "" to also remove from Repo */

    git rm --cached file.txt /* leaves copy of file in Working but removes from Staging and Repo */

    git mv /* rename or move files - then git commit -m "" to move to Repo */
    @@ -53,16 +54,18 @@ git commit -am "text goes here" /* adds all files straight to Repo from Staging

    git checkout -- file.txt /* restore Repo file to Working Directory using current branch */

    git reset --soft HEAD^ /* restore repo file to staging */

    git reset HEAD file.txt /* Move a Stage file out of Stage back to Working */

    git commit --amend -m "message" file.txt /* Change last commit to Repo (only last one can change) */

    /* Reverting --soft --mixed --hard will go back to previous commits*/
    git log /* gets the sha1s so you can see the coomits where you want revert back to */

    git reset --soft sha /* changes Repo but not STaging or Working */
    git reset --soft sha /* changes Repo but not Staging or Working */

    git reset --mixed sha /* changes Repo and STaging but not Working */
    git reset --mixed sha /* changes Repo and Staging but not Working */

    git reset --hard sha /* changes all 3 Tiers */

    @@ -161,7 +164,7 @@ git stash clear /* removes all stash */
    git stash drop stash@{0}

    /* Remotes
    You fetch from the remote server, merge any differences - then push any new to the remote - 3 branches work remote server branch, local origin master and local master
    You can push and fetch to the remote server, merge any differences - then push any new to the remote - 3 branches work remote server branch, local origin master and local master
    Create a repo in GitHub, then add that remote to your local repo */

    @@ -177,7 +180,7 @@ git remote rm origin /* to remove remote */

    /* Push to Remote from Local */

    git push -u origin master
    git push -u origin master /* push to remote(origin) and branch(master)
    /* Cloning a GitHub Repo - create and get the URL of a new repository from GitHub, then clone that to your local repo, example below uses local repo named 'nameoffolder' */

    @@ -189,7 +192,7 @@ git push

    /* Fetch changes from a cloned Repo */

    git fetch origin /* Pulls down latest committs to origin/master not origin, also pull down any branches pushed to Repo
    git fetch origin /* Pulls down latest committs from remote origin/master not origin, also pull down any branches pushed to Repo
    Fetch before you work
    Fetch before you pull
    @@ -199,7 +202,7 @@ Fetch often */

    git merge origin/master

    /* git pull = git fetch + git merge
    git pull /* you can also do git pull which is = git fetch + git merge
    Checkout/Copy a remote branch to local */

  23. neilgee revised this gist Nov 14, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    /* Set up Git Configuration */

    git config --global user.email "neil@coolestguidesontheplanet.com"
    git config --global user.email "you@yourdomain.com"

    git config --global user.name "Neil Gee"
    git config --global user.name "Your Name"

    git config --global core.editor "vi"

  24. neilgee revised this gist Nov 14, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -169,6 +169,8 @@ git remote add origin https://github.com/neilgee/genesischild.git /* origin can

    git remote /* to show all remotes */

    git remote show origin /*to see remote URL*/

    git remote remove origin /* to remove remote */

    git remote rm origin /* to remove remote */
  25. neilgee revised this gist Nov 14, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,7 @@ git diff /* show changes between Working and Repository, no file supplied shows
    git diff --staged /* shows changes between Staged and Respository */

    git rm file.txt /* will remove file from working then git commit -m "" to also remove from Repo */
    git rm --cached file.txt /* leaves copy of file in Working but removes from Staging and Repo */

    git mv /* rename or move files - then git commit -m "" to move to Repo */

    @@ -56,8 +57,8 @@ git reset HEAD file.txt /* Move a Stage file out of Stage back to Working */

    git commit --amend -m "message" file.txt /* Change last commit to Repo (only last one can change) */

    /* Reverting --soft --mixed --hard */
    git log /* gets the sha1s so you can see the coomits where you want to back to */
    /* Reverting --soft --mixed --hard will go back to previous commits*/
    git log /* gets the sha1s so you can see the coomits where you want revert back to */

    git reset --soft sha /* changes Repo but not STaging or Working */

  26. neilgee revised this gist Nov 7, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ git config --global core.excludesfile ~/.gitignore_global /* add to gitconfig */

    /* Stop tracking changes */

    rm --cached file.txt /* leaves copy in Repo and Working */
    git rm --cached file.txt /* leaves copy in Repo and Working */


    /* Track Folders changes
  27. neilgee revised this gist Sep 2, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ git diff /* show changes between Working and Repository, no file supplied shows

    git diff --staged /* shows changes between Staged and Respository */

    git rm file.txt /* will remove file from working then git commit -m "" to move to Repo */
    git rm file.txt /* will remove file from working then git commit -m "" to also remove from Repo */

    git mv /* rename or move files - then git commit -m "" to move to Repo */

  28. neilgee revised this gist Jul 2, 2014. 1 changed file with 81 additions and 81 deletions.
    162 changes: 81 additions & 81 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    /*Set up Git Configuration*/
    /* Set up Git Configuration */

    git config --global user.email "[email protected]"

    @@ -8,208 +8,208 @@ git config --global core.editor "vi"

    git config --global color.ui true

    /*See Git configuration*/
    /* See Git configuration */

    git config --list

    /*initialise a repository*/
    /* to initialise a local repository */

    git init

    /* add a file*/
    /* adds a file to the repo */

    git add

    /*commit the change to git*/
    /* commit the change to git */

    git commit -m "Message goes here"

    /* see the commits*/
    /* see the commits */

    git log

    /*3 Tier Architecture Working - Staging Index - Respository
    /* Git has a 3 Tier Architecture: Working - Staging Index - Respository
    Changes to files are put in a Checksum SHA-1 hash 40digit value containing parent hash, author and message
    Changes to files are put in a Checksum SHA-1 hash 40digit value containing parent hash, author and message.
    HEAD is the latest commit of the checked out branch*/
    HEAD is the latest commit of the checked out branch */

    /* tells which files are not added or committed from Working to Staging to Repository*/
    /* Basic Commands */

    git status
    git status /* the command 'git status' tells which files are not added or committed from Working to Staging to Repository */

    git commit -m "" /*Commits and changes to all files that are in Staging Tier into Repository*/
    git commit -m "" /* Commits and changes to all files that are in Staging Tier into Repository */

    git diff /* show changes between Working and Repository, no file supplied shows all files */
    git diff /* show changes between Working and Repository, no file supplied shows all files */

    git diff --staged /*shows changes between Staged and Respository*/
    git diff --staged /* shows changes between Staged and Respository */

    git rm file.txt /* will remove file from working then git commit -m "" to move to Repo*/
    git rm file.txt /* will remove file from working then git commit -m "" to move to Repo */

    git mv /* rename or move files - then git commit -m "" to move to Repo*/
    git mv /* rename or move files - then git commit -m "" to move to Repo */

    git commit -am "text goes here" /*adds all files straight to Repo from Staging if they have changes - meaning they skip git add*/
    git commit -am "text goes here" /* adds all files straight to Repo from Staging if they have changes - meaning they skip git add */

    git checkout -- file.txt /* restore Repo file to Working Directory using current branch */
    git checkout -- file.txt /* restore Repo file to Working Directory using current branch */

    git reset HEAD file.txt /* Move a Stage file out of Stage back to Working*/
    git reset HEAD file.txt /* Move a Stage file out of Stage back to Working */

    git commit --amend -m "message" file.txt /*Change last commit to Repo (only last one can change)*/
    git commit --amend -m "message" file.txt /* Change last commit to Repo (only last one can change) */

    /*Reverting --soft --mixed --hard*/
    git log /*gets the sha1s so you can see the coomits where you want to back to */
    /* Reverting --soft --mixed --hard */
    git log /* gets the sha1s so you can see the coomits where you want to back to */

    git reset --soft sha /*changes Repo but not STaging or Working*/
    git reset --soft sha /* changes Repo but not STaging or Working */

    git reset --mixed sha /*changes Repo and STaging but not Working*/
    git reset --mixed sha /* changes Repo and STaging but not Working */

    git reset --hard sha /*changes all 3 Tiers*/
    git reset --hard sha /* changes all 3 Tiers */

    git clean -f /*remove untracked files from Working */
    git clean -f /* remove untracked files from Working */

    .gitignore /*ignores files to track in Working / track the .gitignore file*/
    .gitignore /* ignores files to track in Working / track the .gitignore file */

    Global Ignore /*create in home folder */
    Global Ignore /* create in home folder */
    .gitignore_global
    /*Add in */
    /* Add in */
    .DS_Store
    .Trashes
    .Spotlight_V100



    git config --global core.excludesfile ~/.gitignore_global /*add to gitconfig*/
    git config --global core.excludesfile ~/.gitignore_global /* add to gitconfig */

    /*Stop tracking changes*/
    /* Stop tracking changes */

    rm --cached file.txt /*leaves copy in Repo and Working*/
    rm --cached file.txt /* leaves copy in Repo and Working */


    /*Track Folders changes
    /* Track Folders changes
    Add an invisble file to a folder like .gitkeeper then add and commit*/
    Add an invisble file to a folder like .gitkeeper then add and commit */

    /*Commit Log */
    /* Commit Log */
    git ls-tree HEAD
    git ls-tree master
    git log --oneline
    git log --author="Neil"
    git log --grep="temp"

    /*Show Commits*/
    /* Show Commits */

    git show dc094cb /* show SHA1*/
    git show dc094cb /* show SHA1 */

    /*Compare Commits
    /* Compare Commits
    Branches*/
    Branches */

    git branch /* Show local branches * is the one we are on*/
    git branch /* Show local branches * is the one we are on */

    git branch -r /*Shows remote branches*/
    git branch -r /* Shows remote branches */

    git branch -a /*Shows local and remote*/
    git branch -a /* Shows local and remote */

    git branch newbranch /*creates a new branch*/
    git branch newbranch /* creates a new branch */

    git checkout newbranch /*switch to new branch*/
    git checkout newbranch /* switch to new branch */

    git checkout -b oldbranch /*creates and switches to new branch */
    git checkout -b oldbranch /* creates and switches to new branch */


    /*Diff in Branches*/
    /* Diff in Branches */

    git diff master..otherbranch /* shows diff*/
    git diff master..otherbranch /* shows diff */

    git diff --color-words master..otherbranch /* shows diff in color*/
    git diff --color-words master..otherbranch /* shows diff in color */

    git branch --merged /* shows any merged branches*/
    git branch --merged /* shows any merged branches */

    /*Rename Branch*/
    /* Rename Branch */

    git branch -m oldname newname

    /*Delete Branch*/
    /* Delete Branch */

    git branch -d nameofbranch

    /*Merge Branch */
    /* Merge Branch */

    git merge branchname /*be on the receiver branch*/
    git merge branchname /* be on the receiver branch */

    /*Merge Conflicts between the same file on 2 branches are marked in HEAD and other branch*/
    /* Merge Conflicts between the same file on 2 branches are marked in HEAD and other branch */

    git merge --abort /* Abort basically cancels the merge*/
    git merge --abort /* Abort basically cancels the merge */

    /*Manually Fix Files and commit
    /* Manually Fix Files and commit
    The Stash*/
    The Stash */

    git stash save "text message here"

    git stash list /*shows whats in stash*/
    git stash list /* shows whats in stash */

    git stash show -p stash@{0} /*Show the diff in the stash*/
    git stash show -p stash@{0} /* Show the diff in the stash */

    git stash pop stash@{0} /* restores the stash deletes the tash*/
    git stash pop stash@{0} /* restores the stash deletes the tash */

    git stash apply stash@{0} /* restores the stash and keeps the stash*/
    git stash apply stash@{0} /* restores the stash and keeps the stash */

    git stash clear /* removes all stash*/
    git stash clear /* removes all stash */

    git stash drop stash@{0}

    /*Remotes
    /* Remotes
    You fetch from the remote server, merge any differences - then push any new to the remote - 3 branches work remote server branch, local origin master and local master
    Create a repo in GitHub, then add that remote to your local repo*/
    Create a repo in GitHub, then add that remote to your local repo */

    git remote add origin https://github.com/neilgee/genesischild.git /* origin can be named whatever followed by the remote*/
    git remote add origin https://github.com/neilgee/genesischild.git /* origin can be named whatever followed by the remote */

    git remote /*to show all remotes*/
    git remote /* to show all remotes */

    git remote remove origin /*to remove remote*/
    git remote remove origin /* to remove remote */

    git remote rm origin /*to remove remote*/
    git remote rm origin /* to remove remote */

    /*Push to Remote from Local*/
    /* Push to Remote from Local */

    git push -u origin master

    /*Cloning a GitHub Repo - get the URL from GitHub*/
    /* Cloning a GitHub Repo - create and get the URL of a new repository from GitHub, then clone that to your local repo, example below uses local repo named 'nameoffolder' */

    git clone https://github.com/neilgee/genesischild.git nameoffolder

    /*Push to Remote from Local - more - since when we pushed the local to remote we used -u parameter then the remote branch is tracked to the local branch and we just need to use...*/
    /* Push to Remote from Local - more - since when we pushed the local to remote we used -u parameter then the remote branch is tracked to the local branch and we just need to use... */

    git push

    /*Fetch changes from a cloned Repo*/
    /* Fetch changes from a cloned Repo */

    git fetch origin /* Pulls down latest committs to origin/master not origin, also pull down any branches pushed to Repo
    git fetch origin /* Pulls down latest committs to origin/master not origin, also pull down any branches pushed to Repo
    Fetch before you work
    Fetch before you pull
    Fetch often*/
    Fetch often */

    /*Merge with origin/master*/
    /* Merge with origin/master */

    git merge origin/master

    /*git pull = git fetch + git merge
    /* git pull = git fetch + git merge
    Checkout/Copy a remote branch to local*/
    Checkout/Copy a remote branch to local */

    git branch branchname origin/branchname /* this will bring the remote branch to local and track with the remote*/
    git branch branchname origin/branchname /* this will bring the remote branch to local and track with the remote */

    /*Delete branch*/
    /* Delete branch */

    git branch -d branchname

    /*Checkout and switch branch and track to remote*/
    /* Checkout and switch branch and track to remote */

    git checkout -b nontracking origin/nontracking

    /*Remove remote branch*/
    /* Remove remote branch */

    git push origin --delete branch
  29. neilgee revised this gist Mar 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git.css
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    git config --global user.email "[email protected]"

    git config --global user "Neil Gee"
    git config --global user.name "Neil Gee"

    git config --global core.editor "vi"

  30. neilgee revised this gist Mar 21, 2014. 1 changed file with 72 additions and 62 deletions.
    134 changes: 72 additions & 62 deletions git.css
    Original file line number Diff line number Diff line change
    @@ -12,72 +12,82 @@ git config --global color.ui true

    git config --list

    /*initialise a repository*/

    git init /*initialise a repository
    git init

    git add /* add a file
    /* add a file*/

    git commit -m "Message goes here" /*commit the change to git
    git add

    git log /* see the commits
    /*commit the change to git*/

    3 Tier Architecture Working - Staging Index - Respository
    git commit -m "Message goes here"

    /* see the commits*/

    git log

    /*3 Tier Architecture Working - Staging Index - Respository
    Changes to files are put in a Checksum SHA-1 hash 40digit value containing parent hash, author and message
    HEAD is the latest commit of the checked out branch
    HEAD is the latest commit of the checked out branch*/

    git status /* tells which files are not added or committed from Working to Staging to Repository
    /* tells which files are not added or committed from Working to Staging to Repository*/

    git commit -m "" /*Commits and changes to all files that are in Staging Tier into Repository
    git status

    git diff /* show changes between Working and Repository, no file supplied shows all files
    git commit -m "" /*Commits and changes to all files that are in Staging Tier into Repository*/

    git diff --staged /*shows changes between Staged and Respository
    git diff /* show changes between Working and Repository, no file supplied shows all files */

    git rm file.txt /* will remove file from working then git commit -m "" to move to Repo
    git diff --staged /*shows changes between Staged and Respository*/

    git mv /* rename or move files - then git commit -m "" to move to Repo
    git rm file.txt /* will remove file from working then git commit -m "" to move to Repo*/

    git commit -am "text goes here" /*adds all files straight to Repo from Staging if they have changes - meaning they skip git add
    git mv /* rename or move files - then git commit -m "" to move to Repo*/

    git checkout -- file.txt /* restore Repo file to Working Directory using current branch
    git commit -am "text goes here" /*adds all files straight to Repo from Staging if they have changes - meaning they skip git add*/

    git reset HEAD file.txt /* Move a Stage file out of Stage back to Working
    git checkout -- file.txt /* restore Repo file to Working Directory using current branch */

    git commit --amend -m "message" file.txt /*Change last commit to Repo (only last one can change)
    git reset HEAD file.txt /* Move a Stage file out of Stage back to Working*/

    Reverting --soft --mixed --hard
    git log gets the sha1s so you can see the coomits where you want to back to
    git commit --amend -m "message" file.txt /*Change last commit to Repo (only last one can change)*/

    git reset --soft sha /*changes Repo but not STaging or Working
    /*Reverting --soft --mixed --hard*/
    git log /*gets the sha1s so you can see the coomits where you want to back to */

    git reset --mixed sha /*changes Repo and STaging but not Working
    git reset --soft sha /*changes Repo but not STaging or Working*/

    git reset --hard sha /*changes all 3 Tiers
    git reset --mixed sha /*changes Repo and STaging but not Working*/

    git clean -f /*remove untracked files from Working
    git reset --hard sha /*changes all 3 Tiers*/

    .gitignore /*ignores files to track in Working / track the .gitignore file
    git clean -f /*remove untracked files from Working */

    Global Ignore /*create in home folder - .gitignore_global
    .gitignore /*ignores files to track in Working / track the .gitignore file*/

    Global Ignore /*create in home folder */
    .gitignore_global
    /*Add in */
    .DS_Store
    .Trashes
    .Spotlight_V100



    git config --global core.excludesfile ~/.gitignore_global /*add to gitconfig
    git config --global core.excludesfile ~/.gitignore_global /*add to gitconfig*/

    /*Stop tracking changes*/

    rm --cached file.txt /*leaves copy in Repo and Working
    rm --cached file.txt /*leaves copy in Repo and Working*/


    /*Track Folders changes*/
    /*Track Folders changes
    Add an invisble file to a folder like .gitkeeper then add and commit
    Add an invisble file to a folder like .gitkeeper then add and commit*/

    /*Commit Log */
    git ls-tree HEAD
    @@ -88,32 +98,32 @@ git log --grep="temp"

    /*Show Commits*/

    git show dc094cb /* show SHA1
    git show dc094cb /* show SHA1*/

    /*Compare Commits */
    /*Compare Commits
    /* Branches*/
    Branches*/

    git branch /* Show local branches * is the one we are on*/

    git branch -r /*Shows remote branches
    git branch -r /*Shows remote branches*/

    git branch -a /*Shows local and remote
    git branch -a /*Shows local and remote*/

    git branch newbranch /*creates a new branch*/

    git checkout newbranch /*switch to new branch
    git checkout newbranch /*switch to new branch*/

    git checkout -b oldbranch /*creates and switches to new branch */


    /*Diff in Branches*/

    git diff master..otherbranch /* shows diff
    git diff master..otherbranch /* shows diff*/

    git diff --color-words master..otherbranch /* shows diff in color
    git diff --color-words master..otherbranch /* shows diff in color*/

    git branch --merged /* shows any merged branches
    git branch --merged /* shows any merged branches*/

    /*Rename Branch*/

    @@ -125,48 +135,48 @@ git branch -d nameofbranch

    /*Merge Branch */

    git merge branchname /*be on the receiver branch
    git merge branchname /*be on the receiver branch*/

    /*Merge Conflicts between the same file on 2 branches are marked in HEAD and other branch*/

    git merge --abort /* Abort basically cancels the merge
    git merge --abort /* Abort basically cancels the merge*/

    Manually Fix Files and commit
    /*Manually Fix Files and commit
    /*The Stash*/
    The Stash*/

    git stash save "text message here"

    git stash list /*shows whats in stash
    git stash list /*shows whats in stash*/

    git stash show -p stash@{0} /*Show the diff in the stash
    git stash show -p stash@{0} /*Show the diff in the stash*/

    git stash pop stash@{0} /* restores the stash deletes the tash
    git stash pop stash@{0} /* restores the stash deletes the tash*/

    git stash apply stash@{0} /* restores the stash and keeps the stash
    git stash apply stash@{0} /* restores the stash and keeps the stash*/

    git stash clear /* removes all stash
    git stash clear /* removes all stash*/

    git stash drop stash@{0}

    /*Remotes*/
    /*Remotes
    You fetch from the remote server, merge any differences - then push any new to the remote - 3 branches work remote server branch, local origin master and local master
    /*Create a repo in GitHub, then add that remote to your local repo*/
    Create a repo in GitHub, then add that remote to your local repo*/

    git remote add origin https://github.com/neilgee/genesischild.git /* origin can be named whatever followed by the remote
    git remote add origin https://github.com/neilgee/genesischild.git /* origin can be named whatever followed by the remote*/

    git remote /*to show all remotes
    git remote /*to show all remotes*/

    git remote remove origin /*to remove remote
    git remote remove origin /*to remove remote*/

    git remote rm origin /*to remove remote
    git remote rm origin /*to remove remote*/

    /*Push to Remote from Local*/

    git push -u origin master

    /*Cloning a GitHub Repo - get the URL from GitHub
    /*Cloning a GitHub Repo - get the URL from GitHub*/

    git clone https://github.com/neilgee/genesischild.git nameoffolder

    @@ -178,28 +188,28 @@ git push

    git fetch origin /* Pulls down latest committs to origin/master not origin, also pull down any branches pushed to Repo
    /* Fetch before you work
    /* Fetch before you pull
    /* Fetch often
    Fetch before you work
    Fetch before you pull
    Fetch often*/

    /*Merge with origin/master
    /*Merge with origin/master*/

    git merge origin/master

    /*git pull = git fetch + git merge
    /*Checkout/Copy a remote branch to local
    Checkout/Copy a remote branch to local*/

    git branch branchname origin/branchname /* this will bring the remote branch to local and track with the remote
    git branch branchname origin/branchname /* this will bring the remote branch to local and track with the remote*/

    /*Delete branch
    /*Delete branch*/

    git branch -d branchname

    /*Checkout and switch branch and track to remote
    /*Checkout and switch branch and track to remote*/

    git checkout -b nontracking origin/nontracking

    /*Remove remote branch
    /*Remove remote branch*/

    git push origin --delete branch