Git links
This is not an extensive Git howto, it's just a simplification a usage written from an SVN user point of view. To get some more specific recipes:
- Manage public projects on Git: https://www.git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#Public-Small-Project
- Sardana Git Recipes
GIT DONTS
You'll find these commands while googling, don't use them!
DONT USE git pull --squash : it will cause same mess than rebase
DONT USE git pull --rebase $BRANCH : only rebase data from your own commits
DONT USE git rebase --onto $B $D : it will delete commits between B and D
DONT USE git rebase --onto master : it will delete all your local commits
DONT USE git rebase -p origin/$BRANCH : it should apply remote changes on your copy, but it is not so clean as it should, you'll be forced to re-edit all your local commits.
Git Flow - My Recipes to keep Git "easy"
I just oversimplified the flow, but it works
git clone # checkoutgit fetch --all # update repository cachegit checkout develop # change to branchgit pull # merge with repository
git branch feature #create local branch
#or git checkout -b feature origin/develop #for a fork on develop#or git branch -u origin/feature #for an existing branch
git add file.pyvi file.py
git commit -m "message1"
vi file.pygit commit file.py -m "message2"
git commit -a -m "commit all modified files at once"
git reset HEAD^ # remove last commit (if unpushed)
git rebase -i #squash commits before pushing
git push -u origin feature # upload your branch to the repository
#or git push #if the branch already exists
...git fetch --all
git checkout feature && git pull
git checkout develop && git pullgit merge feature
git push #update remotes
git log -p <commit> # see patches for each commit
git show <commit> # see this commit patch
git show --stat <commit> # see files modified in a given commit
When to merge and when to rebase
- Rebase ... NEVER, just if you want to squash/delete commits or when submitting a pull request
- Merge ... to apply a finished feature to the main branch (master or development).
Another interesting feature ... sparse checkouts:
http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/
sparse checkout, and that feature was added in git 1.7.0 (Feb. 2012). The steps to do a sparse clone are as follows:
mkdir <repo>
cd <repo>
git init
git remote add -f origin <url>
This creates an empty repository with your remote, and fetches all objects but doesn't check them out. Then do:
git config core.sparseCheckout true
Now you need to define which files/folders you want to actually check out. This is done by listing them in
.git/info/sparse-checkout, eg:echo "some/dir/" >> .git/info/sparse-checkout
echo "another/sub/tree" >> .git/info/sparse-checkout
Last but not least, update your empty repo with the state from the remote:
git pull origin master