Become a GitHub Wizard
- Store Credentials via your browser
- Undo
git add
before a commit - Undo local changes to files
- Untrack files and remove them from remote
- Ignore everything except a subdirectory
- Delete a branch
- Split a repo into two
- Store your login credentials
- 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 revertgit 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 latergit checkout -- <file>
- Discard local changes (permanently) to a filegit reset --hard
- Discard all local changes to all files permanently
Untrack files and remove them from remote
Thanks to Jonathan Klughertz for the instructions!
- Commit all changes first
- Remove everything from the repository
- Re-add everything
- 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.
- Make a new repo on github (called “newrepo”” in these instructions)
- Make a local copy of your existing repo into a folder called “newrepo”:
git clone <EXISTING REPO URL> newrepo
- Remove the origin:
git remote rm origin
- 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
- Delete the folders you removed from tracking.
- Add the new repo as remote
git remote add origin <NEW REPO URL>
- Push the newly pruned repo
git push origin
Store your login credentials
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