Last active
April 21, 2017 07:50
-
-
Save isaklafleur/a1ef0e0414e3ff6bf22b8eac2e1bb7b9 to your computer and use it in GitHub Desktop.
My Git and GitHub Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============= | |
GIT COMMANDS | |
// ============= | |
Complete Reference: https://git-scm.com/doc | |
// Set up a new git project | |
$ git init | |
// Remove a already created git repository | |
$ rm -rf .git | |
// Add git control on an already created project | |
$ git init nameofalreadycreatedproject | |
// Setting username and email in git | |
$ git config --global user.name "Isak La Fleur" | |
$ git config --global user.email "isak.engdahl@gmail.com" | |
// Add file contents to the index | |
$ git add filename.txt | |
// stages All | |
git add -A | |
// stages new and modified, without deleted | |
git add . | |
// stages modified and deleted, without new | |
git add -u | |
// more about staging | |
http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add | |
// commit files to git | |
$ git commit -m "describe the commit with a short comment here." | |
// Show commit logs | |
$ git log | |
// Show the working tree status (obtains a summary of which files have changes that are staged for the next commit) | |
$ git status | |
// Create a new branch | |
// Specifying -b causes a new branch to be created | |
$ git checkout -b newbranchname | |
// Switch to a another branch | |
$ git checkout testingnewbranch | |
// switch back to the master branch | |
$ git checkout master | |
// display all branches and see what branch you are working in | |
$ git branch | |
// merge branch to master | |
$ git merge testingnewbranch | |
// display the history of commits using the alias | |
$ git lg1 | |
$ git lg2 | |
// configure the .gitconfig file | |
// go to user home "cd ~" (on linux/mac) folder and type | |
$ nano .gitconfig | |
// add the following code end of the file. | |
[alias] | |
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all | |
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all | |
lg = !"git lg1" | |
// exit file with CTRL + X | |
// save changes with Y + ENTER | |
// ============= | |
GITHUB COMMANDS | |
// ============= | |
Complete Reference: https://help.github.com/ | |
// add the local git repository files to GitHub | |
$ git remote add origin https://github.com/isaklafleur/gittesting.git | |
// change remote's URL | |
git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git | |
// display where you are | |
$ git remote | |
// Display remote versions | |
$ git remote -v | |
// Push commit to GitHub | |
$ git push -u origin master | |
// Complete process. The -f option on git push forces the push. see more here: http://stackoverflow.com/questions/17291995/push-existing-project-into-github | |
$ git init | |
$ git add . | |
$ git commit -m "Initial commit" | |
$ git remote add origin <project url> | |
$ git push -f origin master | |
// Display if there are data on GitHub | |
$ git fetch | |
// Pull all data from GitHub | |
$ git pull | |
// Clone a already created repository on GitHub. Important: First change the current working directory to the location where you want the cloned directory to be made. | |
// Run command | |
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY | |
$ git clone https://github.com/isaklafleur/gittesting.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment