Skip to content

Instantly share code, notes, and snippets.

@kosperera
Last active November 14, 2023 05:04
Show Gist options
  • Save kosperera/22d60f47a553a0839afcfd071da86e3d to your computer and use it in GitHub Desktop.
Save kosperera/22d60f47a553a0839afcfd071da86e3d to your computer and use it in GitHub Desktop.
Awesome Git Commands

Hard Reset Local branch to the origin/remote.

This basically discard all changes, commits, etc. which are not pushed to remote yet, and pull the latest version from the remote.

git fetch origin master
git reset --hard FETCH_HEAD
git clean -df

Managing sub-module repos.

This will add external repositories as submodules into the current repository.

git submodule add <repo-url> <sub-module-name>

This is how you clone a repository that contains submodules.

git clone -recurse-submodules -j8 <main-repo-url>
@kosperera
Copy link
Author

kosperera commented Nov 14, 2023

Rename master to main.

This is going to be useful for legacy repos that were created sometime ago.

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

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