Link Search Menu Expand Document

Become a GitHub Wizard

  1. Store Credentials via your browser
  2. Undo git add before a commit
  3. Undo local changes to files
  4. Untrack files and remove them from remote
  5. Ignore everything except a subdirectory
  6. Delete a branch
  7. Split a repo into two
  8. Store your login credentials
  9. Use forks to organize your workflow

Store Credentials via your browser

I use Github CLI to do this. It’s very convenient!

Undo git add before a commit

Documentation from freeCodeCamp

  • git reset <file> for each file you want to revert
  • git reset to unstage all changes.

Undo local changes to files

Documentation from GitLab

  • git stash - Discard all local changes, but save them for possible re-use later
  • git checkout -- <file> - Discard local changes (permanently) to a file
  • git reset --hard - Discard all local changes to all files permanently

Untrack files and remove them from remote

Thanks to Jonathan Klughertz for the instructions!

  1. Commit all changes first
  2. Remove everything from the repository
  3. Re-add everything
  4. Commit and push
git add .
git commit -m "added a few things to gitignore"
git rm -r --cached .
git add .
git commit -m ".gitignore fix"
git push

Ignore everything except a subdirectory

Thanks to this stack overflow post for the instructions!

/*
/*/
!/bin/

Delete a branch

Thanks to freeCodeCamp for the instructions:

// delete branch locally
git branch -d <branchName>

// delete branch remotely
git push origin --delete <branchName>

Split a repo into two

Instructions from Atlassian, with extra instructions also from Atlassian.

  1. Make a new repo on github (called “newrepo”” in these instructions)
  2. Make a local copy of your existing repo into a folder called “newrepo”:
    git clone <EXISTING REPO URL> newrepo
    
  3. Remove the origin:
    git remote rm origin
    
  4. Remove folders you don’t want in the new repo from tracking (this might take a while):
    git filter-branch --index-filter "git rm -r --cached --ignore-unmatch <FOLDER>" --prune-empty -f
    
  5. Delete the folders you removed from tracking.
  6. Add the new repo as remote
    git remote add origin <NEW REPO URL>
    
  7. Push the newly pruned repo
    git push origin
    

Store your login credentials

Here’s how to do it.

Use forks to organize your workflow

when multiple people are working on a project, forks make it easier to keep track of the different changes people are making.

Basics

I use the standard github fork workflow

If something goes wrong, here are some lesser used commands

Turning any repo into a fork

This is from a great tutorial by handong1587.

Recently I needed to do this for Marlin Firmware, since I have a variety of devices I’m developing on that us different versions:

git clone https://github.com/MarlinFirmware/Marlin.git
cd Marlin

Now create a new repo on github. Mine was “marlin-cr10s”

git remote rename origin upstream
git remote add origin https://github.com/cbteeple/marlin-cr10s.git
git push -u origin