title | category | layout | updated |
---|---|---|---|
Git branches |
Git |
2017/sheet |
2017-09-20 |
{: .-three-column}
git checkout -b $branchname
git push origin $branchname --set-upstream
Creates a new branch locally then pushes it.
git fetch origin
git checkout --track origin/$branchname
Gets a branch in a remote.
git remote prune origin
Deletes origin/*
branches in your local copy. Doesn't affect the remote.
git branch --list
Existing branches are listed. Current branch will be highlighted with an asterisk.
git branch -a --merged
List outdated branches that have been merged into the current one.
git branch -d $branchname
Deletes the branch only if the changes have been pushed and merged with remote.
git branch -D $branchname
git branch -d $branchname
Note: You can also use the -D flag which is synonymous with --delete --force instead of -d. This will delete the branch regardless of its merge status. Delete a branch irrespective of its merged status.
git push origin --delete :$branchname
Works for tags, too!
git show-ref HEAD -s
git reset --hard
git reset --hard $commit_id
# Now push to your branch
git push --force