Skip to content

Instantly share code, notes, and snippets.

@nardsqq
Last active February 5, 2020 06:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nardsqq/ce0593c9c0a1838249657008a3627534 to your computer and use it in GitHub Desktop.
Save nardsqq/ce0593c9c0a1838249657008a3627534 to your computer and use it in GitHub Desktop.
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