Skip to content

Instantly share code, notes, and snippets.

@patrickfox
Last active May 8, 2023 14:49
Show Gist options
  • Save patrickfox/922de5922817b4b5e758e4cc08b980f4 to your computer and use it in GitHub Desktop.
Save patrickfox/922de5922817b4b5e758e4cc08b980f4 to your computer and use it in GitHub Desktop.

Remove remote folders already in the repo but since added to my .gitignore

Oops! I committed and pushed some crap that I didn't mean to.

git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master

Deploy part of your repo to another branch/repo

Ever have a build folder that you need to deploy to another repo? Use git subtree split !

In this example, I am grabbing my build folder, splitting it, and pushing it to my gh-pages branch. Caution: This will completely overwrite what is already in the gh-pages branch

git subtree split --prefix build -b gh-pages-temp
git push -f origin gh-pages-temp:gh-pages
git branch -D gh-pages-temp

More info: One line deployment to GH pages

Remove a file from a PR'd branch

If you updated a file that already existed and want to remove it from the PR:

Assume you're working on a branch off of staging, and you PR'd a file named validate_model.py.

To remove this file from the PR and revert its changes, simply do:

git checkout staging -- validate_model.py

and then re-commit and push upstream.

Create a Branch

This actually creates and checks out a new branch.

git checkout -b {branch name}

Push a new branch upstream

git push -u origin <new local branch>

List branches

git branch -a - lists all branched

git remote show origin - lists

Change Origin

See: https://help.github.com/articles/changing-a-remote-s-url/

git remote -v - show all remote paths

git remote set-url origin {ssh path to origin gh repo} - set url for origin

git remote set-url upstream {ssh path to upstream gh repo} - set url for upstream

Set remote upstream for a fork

See: https://help.github.com/articles/configuring-a-remote-for-a-fork/

git remote add upstream {ssh path to remote gh repo}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment