🫐 Commands
Git + GitHub

Git & GitHub

  • git init initializes a local git directory
  • rm -fr .git removes a local git directory
  • git status status of staging area
  • git log show log of changes
  • git diff filename.txt see recent changes made to code

Navigate

  • git branch lists all branches
  • git branch branchName creates a new branch
  • git checkout branchName move into branch
  • git checkout -b branchName creates a new branch and moves into it

Commit

  • git add <filename> add file to staging area
  • git add . add all files that aren’t currently staged
  • git reset removes all files from git status staging area
  • git commit -m “change message” commits files locally
  • git commit -m “title” -m “longer description” add a description of changes
  • git commit --amend -m "change message" amend a commit and change the commit message
  • git commit --amend --no-edit amend a commit without changing the commit message

How to write a good commit message (opens in a new tab)

Local branches

  • git checkout main then git branch -D <branchname> delete local branch

Remote branches

Origins

  • git remote add origin <repository-url> add remote origin
  • git remote remove origin remove remote origin
  • git remote set-url origin url update remote origin
  • git remote -v view connected remote repositories

Pull and push

  • git pull origin main pull remote main branch into branch
  • git push origin main push your branch to the remote repository main branch
  • git push origin branchName push your branch to the remote repository
  • git checkout -b new-branch origin/branchname checkout remote branch, good for testing PRs

Problems / Solutions

Wont push to a remote repo that has a README

git fetch --all
git rebase origin/main

Resources