| layout | page | ||||
|---|---|---|---|---|---|
| title | Git recipes | ||||
| date | 2013-05-05 12:00 | ||||
| permalink | /pages/git-recipes.html | ||||
| page-class | page-git-recipes | ||||
| comments | true | ||||
| categories |
|
||||
| tag |
|
||||
| keywords |
|
Short, to the point, example driven recipes for git.
git push origin new-branch
Where origin is your remote name and new-branch is the name of the local branch you want to push.
git checkout -b new-branch
Where new-branch is the name of the branch you want to create and checkout.
git push origin :branch-name
Notice the : before the branch name. Where origin is your remote name and branch-name is the name of the remote branch to delete.
git branch -d branch-name
Where branch-name is the name of the local branch to delete. If the branch is not fully merged, use -D to force removal.
git branch -m current-branch new-branch
Where current-branch is the name of the current branch you want to rename and new-branch the new name.
git branch feature-branch
git reset --hard HEAD~1
git
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "<old-name>" ];
then
GIT_COMMITTER_NAME="<new-name>";
GIT_AUTHOR_NAME="<new-name>";
GIT_COMMITTER_EMAIL="<new-email>";
GIT_AUTHOR_EMAIL="<new-email>";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
Where <old-name> is the name of the committer you want to fix and <new-name> and <new-mail> are the new name and email address of the committer.
git remote set-url origin <new-url>
Where <new-url> is the new origin, eq: https://pjvds@bitbucket.org/pjvds/healthcheck.git.
git reset HEAD <file>
Where <file> is the path to the file. This will unstage the file by removing it from the current index but leaves the content changes. A git status will show the file as untracked.