Skip to content

Instantly share code, notes, and snippets.

@AdilHindistan
Last active August 29, 2015 13:56
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 AdilHindistan/9274447 to your computer and use it in GitHub Desktop.
Save AdilHindistan/9274447 to your computer and use it in GitHub Desktop.
## Resources ## Pro Git Book: http://git-scm.com/book
## Code school: https://www.codeschool.com/courses/try-git
## git stash:
## Sometimes when you go to pull you may have changes you don't want to commit just yet. One option you have, other than committing, is to stash the changes.
## Use the command 'git stash' to stash your changes, and 'git stash apply' to re-apply your changes after your pull.
## -u = remember, remote=origin, branch=master
git push -u origin master
## HEAD is a pointer to our latest commits. To diff between our latest commits and master branch
git diff HEAD
## changes we staged
git diff --stages
## unstage using git reset
git reset path/tofile
## '--' means that there are no more options after '--'. Without it, if what comes after is a branch name, git will switch to that branch
## below will get rid of everything since the last commit of 'filename'
git checkout -- filename
## create a branch when working on a bug or feature, which you can then merge into main
git branch my_branch_name
## to see current branches
git branch
## to change to branch my_branch_name
git checkout my_branch_name
## Recursively remove files and folders. It also stages removal of those files and folders
git rm -r folder_to_remove
## Merge changes I made in the branch to the master
git merge my_branch_name
## Get rid of my branch, now that changes are merged
git branch -d my_branch_name
## if you don't want to merge your branch and want to delete it -d does not work on unmerged. Either add --force (-f) or specify -D (=-d -f)
git branch -d -f bad_code_branch
## Keep in touch with the source of what you forked
## Assign the original repository to a remote called upstream
git remote add upstream https://github.com/person/project.git
## pull in changes not present in my local repo, without modifying files
git fetch upstream
## Merge any changed fetched into my working files
git merge upstream/master
## Add and commit at the same time using alias
git config --global alias.ac '!git add -A && git commit'
## Differences between git-add (From <http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add>)
"git add -A" is equivalent to "git add .; git add -u".
The important point about "git add ." is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.
"git add -u" looks at all the currently tracked files and stages the changes to those files if they are different or if they have been removed. It does not add any new files, it only stages changes to already tracked files.
"git add -A" is a handy shortcut for doing both.
Summary:
• git add -A stages All
• git add . stages new and modified, without deleted
• git add -u stages modified and deleted, without new
## initialize an empty git repo
git init my_new_repo
cd my_new_repo
git config user.name username
git config user.email email@com
git commit --allow-empty -m "initial empty commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment