#organize
{Git commands: an illustration](https://maggieappleton.com/git-mistakes)
Checkout a New Branch
git checkout -b new-branch
#This will make a new branch if it doesn't exist already
Rename a Local Branch
Go to directory and branch you want to name ```
git checkout branch-name
Use -m
to change name
git branch -m new-branch-name
alternatively:
git branch -m old-name new-name
Deleting the master branch
git branch -m master main
git push --set-upstream origin main
git branch -D master
Changing master
to main
in git init
This will change 1 the default branch to main
:
git config --global init.defaultBranch main
Set Upstream Branch
git push --set-upstream <remote> <branch>
Add Local Repo to GitHub
- Create a repo on GitHub to connect to.
- Turn selected directory into a local repo then stage and commit files (if you haven't already):
git init -b main
git add . && git commit -m "initial commit"
- Copy SSH link on Github repo
- !github-link-img.png Private or Broken Links
The page you're looking for is either not available or private!
- !github-link-img.png Private or Broken Links
- Add remote SSH link to git, so it knows where to push the code, then verify:
git remote add origin <remote-url> git remote -v
- Push local repo to GitHub repo:
git push origin main
Force Push to Github
git push --force origin main
Upgrading git
sudo add-apt-repository ppa:git-core/ppa -y
sudo apt update
sudo apt install git
To check that version has been updated:
git --version
You may run into an error about a missing apt-pkg module. You can find the fix for this Python 3#Missing apt file |
here Private or Broken Links The page you're looking for is either not available or private! . |
-
If
git --version
returns with a version earlier than 2.28, you must before the line will work. ↩