Skip to content

Instantly share code, notes, and snippets.

@sl4m
Created February 22, 2010 04:57
Show Gist options
  • Save sl4m/310807 to your computer and use it in GitHub Desktop.
Save sl4m/310807 to your computer and use it in GitHub Desktop.
## basic workflow
* edit files
* stage the changes
* review your changes
* commit the changes
## basic[er] workflow
* edit files
* stage and commit
## working directory -> index -> repository
* working directory == local directory
* index = staging
* repository = local/remote repositories
## git commands example (basic workflow)
git status
git add .
git commit -m "commit message"
git push origin master
## git commands explained
git status => shows new/modified files on working directory
git add => adds new/modified files to index
git commit => adds staged files to local repository
git push => pushes changes from local repository to remote repository
## git commands example (basic[er] workflow)
git status
git commit -a
git push origin master
## git commands explained
git commit with 'a' switch stages and commits *only* modified files to local repository
## most common git commands
git --version
gets version of git
git [command] --help <or> git help [command]
gets help on specific command
git config --global user.name "[name]"
git config --global user.email [email]
git config --list
shows config list
git init
creates an empty git repository or reinitializes an existing one
touch
creates an empty file
.gitignore
file used to ignore files
exclude
file that contains certain excludes
git add .
takes working dir, all sub-dirs and all files to stage
git add -u
stages only files git knows about
git status
to see what has not been staged and/or committed
git reset HEAD [file_name]
removes a file from staging
git commit -m '[comment]'
commits staged items to local repo
git ls-files
checks files that have been committed to local repo
git revert HEAD
reverts the most recent commit
git remote add origin [email protected]:[user.name]/[remote.repo].git
adds remote repo as 'origin' alias
git remote show origin
check to make sure push was successful
git remote show -n origin
checks the local cache, no passphrase needed
git push [repo] [branch]
pushes changes from local repo to remote repo
git clone git://github.com/[project_name]/[repo_name].git
used by anyone (public) and can only pull objects from repo
git clone [email protected]:[project_name]/[repo_name].git
used by owner/collaborators of [project_name] and can push and pull from repo
git fetch [remote.repo]
fetches all objects from [remote.repo] and stores them locally
git merge [branch_name]
merges branch with default
git pull [remote.repo] [branch_name]
fetches and merges (git fetch and git merge)
git branch
displays branches of the project
git branch [branch_name]
creates a new branch
git checkout [branch_name]
switches branch
git diff
shows what is not staged
git diff --cached
shows what is staged
git diff [branch_1] [branch_2]
runs a diff against both branches and displays results
git log
full history of the project including email addresses of collaborators
git log [repo]/[branch_name]
shows what is committed but not yet pushed
gitk --all
opens up the tree visualizer tool for the project
git stash
git stash save
git stash list
git stash drop [stash]
git stash pop
git stash apply
git blame [file_name]
show what revision and author last modified each line of a file
git bisect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment