First off lets start with some simples rules.
- Don't commit directly to master, only merge to master.
- Only merge to master if the source branch is stable.
- Never fucking force push (
-f
or--force
) to fucking anything ever. - Don't use
rm
or your file manager to delete files. Usegit rm
instead. - Linus Torvalds is the Supreme Leader. All hail the Supreme Leader!
Tracking changes is what git is all about. Commits hold a set of changes, or at least one change, and are used to describe changes within them. Merges are a way of taking all of the commits from a source branch and applying them to target branch. See branches
.
git pull
Get remote changes.
git add .
Add all untracked files to git.
git add file_path
Add specific files to git.
git rm [-r] file_path [--cached]
Remove file from git. For folders use -r
. To leave the file in your local file system use --cached
.
git commit -m "Message goes here" [-m "Description goes here"]
Commit changes. Use a second -m
argument to add a description.
git push
Push commits.
git status
Check status of local git.
git reset --hard HEAD
Blow away all unpublished changes and commits from the current branch. Essentially resets your local git to the last pulled state.
git reset --soft HEAD^
Uncommitted all unpublished commits.
Branches are a way of separating changes by multiple parties, or the same party with multiple distinct intents, so as to avoid collision and nasty merge conflicts. The default branch is of course master
. To switch branches you can NOT have any uncommitted changes in the current branch, to get around this you can stash
your changes without committing them.
git branch
Show current branch.
git checkout branch_name
Switch to an existing branch.
git checkout -b branch_name
Create a new branch based on the current one.
git pull origin branch_name
Pull changes from another branch into the current one.
git checkout origin/branch_name -- file_path
Pull single file from another branch into the current one.
By stashing uncommitted changes, you can freely checkout other branches. You can even unstash changes in a different branch than the one you stashed them from. Useful if you realize you made changes on the wrong branch.
git stash
Stash away uncommitted changes.
git stash pop
Unstash last set of stashed changes.