Quick reference for git / GitHub daily workflow
- create the local branch
git checkout -b branch_name- push it to remote and set upstream
git push -u origin branch_name(if you have an existing tracking branch already set on the branch you're pushing, and push.default is set to upstream, this will not do what you think it will do.
It will try to push over the existing tracking branch. In this case do branch --unset-upstream first)
git push origin :branch_name(or, more verbosely, git push origin --delete branch_name)
git branch -d branch_namegit remote prune origin [--dry-run]assumed your remote is named "origin":
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remoteold_branch can be omitted if renaming the current branch
assumed your remote is named "origin"
git branch --set-upstream origin/fooOr, if local branch foo is not the current branch:
git branch --set-upstream origin/foo fooOn git 1.8 you can use -u instead of --set-upstream
git submodule add --name "Submodule name" -- https://github.com/drAlberT/vimcfg4php.git path/to/submodule git submodule deinit path/to/submodule
git rm path/to/submodule
# or, if you want to leave it in your working tree
git rm --cached path/to/submodule
rm -rf .git/modules/path/to/submodulechoose among --local, --global, --system; specifing nothing means "local"
- get config
git config --local -l- set value
git config --local user.name drAlberTgit config --global user.name "Your Name"
git config --global user.email [email protected]
git config --global credential.helper 'cache --timeout=86400'git fetch origin
git reset --hard origin/master
git clean -f -dgit checkout <version_hash|branch> -- path/filegit config --global user.name "Your Name"
git config --global user.email [email protected]After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-authorUse this bash script to search and replace every occurrence of given email(s) into the current checkout.
- create a fresh, bare clone of your repository:
git clone --bare https://github.com/user/reponame.git FIXME
cd FIXME- if needed get the list of users having contributed with their emails
git shortlog -sneor, to get only the emails
git shortlog -sne | sed 's/^.*<\([^>]\+\)>.*$/\1/' | sort | uniq- run the script git-author-rewrite.sh
- review the result
- push the corrected history:
git push --force --tags origin 'refs/heads/*'- remove the local copy of the repo
cd ..
rm -rf FIXMEgit checkout <feature_branch>
git fetch <upstream>
git rebase <upstream>/<main_branch>
git push --force-with-lease