add a folder that was already committed to .gitignore:
- add the folder to a .gitignore file
<folder_name>/
{shell}git rm -r --cached <folder_name>/
We then require another commit (because the files are gone)
Why does this work?
{shell}git rm
This removed the files or folders from the staging area in git, to stop them from being tracked by git after the next commit
-r
: recursive flag
--cached
: will remove the specified folder from the staging area, without actually deleting the files from your local working directory. Git will stop tracking them, but they will still be there. If we didn't add these flags, it would've deleted the files.
git rm guarantees that git is aware of the changes. If we used rm directly, it might still work, but we would need additional git commands. It can then lead to strange situations where the files are deleted but still tracked by git.
Delete and overwrite local branch with remote
git fetch
git reset --hard @{u}
One machine, multiple git accounts:
Via multiple ssh keys and a config file:
You then stop pulling or pushing to https://github.com
, but you push to https://github.com-<INSERT WHATEVER YOU DEFINED IN CONFIG HERE>