Useful Git commands

Frequently used git commands collection

# Adding a remote repository
git remote add origin https://github.com/user/repo.git

# Check remote repository settings.
git remote -v

#Changing a remote repository's URL
git remote set-url origin https://github.com/user/repo.git

# Use branch help command
git branch --help

# Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream-to.
git branch -d <local-branch> 

# Shortcut for --delete --force.
git branch -D <local-branch>

# Delete a remote branch
git push origin -d branch-name

Reference:

https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories

Scroll to Top