Skip to content

Instantly share code, notes, and snippets.

@nardsqq

nardsqq/git.md

Last active Feb 5, 2020
Embed
What would you like to do?
A collection of helpful git commands when working in a team of developers

Git

A collection of helpful git commands when working in a team of developers

To check your repository's remote URL:
git config --get remote.origin.url

Renaming branches

Renaming a separate branch:
git branch -m <old_name> <new_name>

Renaming current branch:
git branch -m <new_name>

Pushing changes to remote:
git push -u origin <new_name>
git push origin :<old_name>

Deleting branches

Delete a branch locally:
git branch -d live-branch/branch-name

Force a branch delete:
git branch D live-branch/branch-name

Delete a remote branch:
git push remote :live-branch/branch-name

Fetch latest and remove obsolete tracking changes:
git fetch --all --prune

Viewing tracked branches

View both local and remote branches:
git branch -a

View all of your remote branches only:
git branch -r

View full output of fetch url, push url, HEAD branch, tracked remote branches, local branches configured for git pull and refs configured for git push
git show remote origin

Updating branches

Updating and rebasing from master:
git pull origin master --rebase

Pushing rebased branch with lease:
git push --force-with-lease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment