git

#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

  1. Create a repo on GitHub to connect to.
  2. 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"
  1. 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!
  2. 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 
    
  3. 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!
.
  1. If git --version returns with a version earlier than 2.28, you must before the line will work.