Skip to content

Instantly share code, notes, and snippets.

@nas
Last active September 3, 2015 15:24
Show Gist options
  • Save nas/168991 to your computer and use it in GitHub Desktop.
Save nas/168991 to your computer and use it in GitHub Desktop.
Useful git commands
# new branch from stash
git stash create new-branch stash@{0}
# push a local branch to repo if does not exist remotely
git push origin branch_name:refs/heads/branch_name
# to start tracking a branch
git branch --track branch_name origin/branch_name
# create remote git branch from head of master
git push origin origin:refs/heads/branch_name
# create a remote branch from another branch's head
git push origin existing_branch_name:new_branch_name
# checkout a remote tracking branch
git checkout -b branch_name origin/branch_name
# manually make the local non tracking branch to track the remote branch
git config branch.branch_name.remote origin
git config branch.branch_name.merge rename_task
# delete a remote branch
git branch -d -r origin/branch_name
git push origin :branch_name
# to only push the current branch to the remote repository
git push origin branch_name OR
git push origin HEAD
# to keep history clean
git commit -m "commit message"
git fetch
run tests
if everything is fine
git push origin branch_name
else
git rebase origin/branch_name
git push origin branch_name
end
# to commit a patch
git add -i
then select the option by typing p
and follow the rest
# to amend
git commit --amend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment