Skip to content

Instantly share code, notes, and snippets.

@mariamihai
Last active March 20, 2022 12:01
Show Gist options
  • Save mariamihai/f9b95a4c5da3e6eb6e81cf095e07bb2b to your computer and use it in GitHub Desktop.
Save mariamihai/f9b95a4c5da3e6eb6e81cf095e07bb2b to your computer and use it in GitHub Desktop.
Git commands for different situations

Git commands





Merging multiple repositories

Start with a repo that has at least one commit (it contains a master / main branch).

For simplicity, make sure the new repo files are in a folder.

Add a remote for the repo to be merged:

git remote add -f another_repo

Merge the files into current repo master branch:

git merge another_repo/master --allow-unrelated-histories

Remove the remote for the added repo:

git remote remove another_repo

The history is now concatenated and the second repository can be deleted.

Change default branch from main to master

Create master branch locally with history from main:

git branch -m main master

Push master:

git push -u origin master

Sswitch HEAD:

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master

Change the default branch on GitHub to master under Settings > Branches > Default branch

Delete the main branch on the remote

git push origin --delete main

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