Create a GIT repository in local folder:
git init
Clone a remote GIT repository to local:
git clone /path/to/repository
...when using a remote server:
git clone username@host:/path/to/repository
Add new file to the index:
git add <filename>
Add all files to the index:
git add *
Commit the changes:
git commit -m "Commit message"
Pull the changes from the remote repository:
git pull
Push the local changes:
git push origin master
To connect your repository to a remote server (i.e. didn't clone an existing repository):
git remote add origin <server>
Branches
Create a new branch, based on the master branch:
git checkout -b new_branch
Switch back to master:
git checkout master
Delete the branch:
git branch -d new_branch
Push the branch to the remote server:
git branch origin <branch>
Merging
To merge another branch into your active branch (e.g. master):
git merge <branch>
Preview changes before merging:
git diff <source_branch> <target_branch>
After fixing conflicts:
git add <filename>
Fixing
Replace local changes with latest in HEAD:
git checkout -- <filename>
Note: When tested yourself...
1. Created new file locally
2. Edited file with text "1234"
3. Added, and then committed locally
4. Edited file again and changed to "ABCD"
5. "git checkout -- <filename>"
6. The file now was "1234" and nothing to commit, so it's as if "ABCD" didn't happen
This was all local, nothing sent to remote
To drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it:
git fetch origin
git reset --hard origin/master
To revert the above hard reset:
git reflog
git reset HEAD@{x}
...where x refers to which number in the reflog you want to go back to. Probably {1}
http://rogerdudler.github.io/git-guide/