Created
August 6, 2013 16:53
-
-
Save aaronsaunders/6166332 to your computer and use it in GitHub Desktop.
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 init | |
# Print & Set Some Basic Config Variables (Global) | |
$ git config --global user.email | |
$ git config --global user.name | |
$ git config --global user.email "[email protected]" | |
$ git config --global user.name "My Name" | |
# Quickly check available commands | |
$ git help | |
# Check all available commands | |
$ git help -a | |
# Command specific help - user manual | |
# git help <command_here> | |
$ git help add | |
$ git help commit | |
$ git help init | |
# Will display the branch, untracked files, changes and other differences | |
$ git status | |
# To learn other "tid bits" about git status | |
$ git help status | |
# add a file in your current working directory | |
$ git add HelloWorld.java | |
# add a file in a nested dir | |
$ git add /path/to/file/HelloWorld.c | |
# Regular Expression support! | |
$ git add ./*.java | |
# list existing branches & remotes | |
$ git branch -a | |
# create a new branch | |
$ git branch myNewBranch | |
# delete a branch | |
$ git branch -d myBranch | |
# rename a branch | |
# git branch -m <oldname> <newname> | |
$ git branch -m myBranchName myNewBranchName | |
# edit a branch's description | |
$ git branch myBranchName --edit-description | |
# Checkout a repo - defaults to master branch | |
$ git checkout | |
# Checkout a specified branch | |
$ git checkout branchName | |
# Create a new branch & switch to it, like: "git branch <name>; git checkout <name>" | |
$ git checkout -b newBranch | |
# Clone learnxinyminutes-docs | |
$ git clone https://github.com/adambard/learnxinyminutes-docs.git | |
# commit with a message | |
$ git commit -m "Added multiplyNumbers() function to HelloWorld.c" | |
# Show difference between your working dir and the index | |
$ git diff | |
# Show differences between the index and the most recent commit. | |
$ git diff --cached | |
# Show differences between your working dir and the most recent commit | |
$ git diff HEAD | |
# Thanks to Travis Jeffery for these | |
# Set line numbers to be shown in grep search results | |
$ git config --global grep.lineNumber true | |
# Make search results more readable, including grouping | |
$ git config --global alias.g "grep --break --heading --line-number" | |
# Search for "variableName" in all java files | |
$ git grep 'variableName' -- '*.java' | |
# Search for a line that contains "arrayListName" and, "add" or "remove" | |
$ git grep -e 'arrayListName' --and \( -e add -e remove \) | |
# Show all commits | |
$ git log | |
# Show X number of commits | |
$ git log -n 10 | |
# Show merge commits only | |
$ git log --merges | |
# Merge the specified branch into the current. | |
$ git merge branchName | |
# Always generate a merge commit when merging | |
$ git merge --no-ff branchName | |
# Renaming a file | |
$ git mv HelloWorld.c HelloNewWorld.c | |
# Moving a file | |
$ git mv HelloWorld.c ./new/path/HelloWorld.c | |
# Force rename or move | |
# "existingFile" already exists in the directory, will be overwritten | |
$ git mv -f myFile existingFile | |
# Update your local repo, by merging in new changes | |
# from the remote "origin" and "master" branch. | |
# git pull <remote> <branch> | |
$ git pull origin master | |
# Push and merge changes from a local repo to a | |
# remote named "origin" and "master" branch. | |
# git push <remote> <branch> | |
# git push => implicitly defaults to => git push origin master | |
$ git push origin master | |
# Rebase experimentBranch onto master | |
# git rebase <basebranch> <topicbranch> | |
$ git rebase master experimentBranch | |
# Reset the staging area, to match the latest commit (leaves dir unchanged) | |
$ git reset | |
# Reset the staging area, to match the latest commit, and overwrite working dir | |
$ git reset --hard | |
# Moves the current branch tip to the specified commit (leaves dir unchanged) | |
# all changes still exist in the directory. | |
$ git reset 31f2bb1 | |
# Moves the current branch tip backward to the specified commit | |
# and makes the working dir match (deletes uncommited changes and all commits | |
# after the specified commit). | |
$ git reset --hard 31f2bb1 | |
# remove HelloWorld.c | |
$ git rm HelloWorld.c | |
# Remove a file from a nested dir | |
$ git rm /pather/to/the/file/HelloWorld.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment