Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Last active April 21, 2017 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaklafleur/a1ef0e0414e3ff6bf22b8eac2e1bb7b9 to your computer and use it in GitHub Desktop.
Save isaklafleur/a1ef0e0414e3ff6bf22b8eac2e1bb7b9 to your computer and use it in GitHub Desktop.
My Git and GitHub Cheat Sheet
// =============
// =============
Complete Reference:
// 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 "Isak La Fleur"
$ git config --global ""
// 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
// 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.
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
// =============
// =============
Complete Reference:
// add the local git repository files to GitHub
$ git remote add origin
// change remote's URL
git remote set-url origin
// 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:
$ 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
$ git clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment