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_name
git 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 remote
old_branch
can be omitted if renaming the current branch
assumed your remote is named "origin"
git branch --set-upstream origin/foo
Or, if local branch foo is not the current branch:
git branch --set-upstream origin/foo foo
On 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/submodule
choose among --local
, --global
, --system
; specifing nothing means "local"
- get config
git config --local -l
- set value
git config --local user.name drAlberT
git config --global user.name "Your Name"
git config --global user.email you@example.com
git config --global credential.helper 'cache --timeout=86400'
git fetch origin
git reset --hard origin/master
git clean -f -d
git checkout <version_hash|branch> -- path/file
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
Use 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 -sne
or, 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 FIXME
git checkout <feature_branch>
git fetch <upstream>
git rebase <upstream>/<main_branch>
git push --force-with-lease