Tag Archive : GIT


GIT: Remove File History

October 24, 2019 | Coding, System Administration | No Comments


Ever accidentally commit a file that you meant to have in your .gitignore? Perhaps a file which includes an API key? It’s easier than you are probably thinking.

$ git rm --cached the-file-i-want-to-remove
$ git commit --amend -CHEAD
$ git filter-branch --force --index-filter "git rm --cached --ignore-unmatch FILE-TO_REMOVE" --prune-empty --tag-name-filter cat -- --all

But, you’re better off just not committing files that you don’t want in the first place.


Congratulations on using a Version Control System for your code! Believe it or not, not everyone is, well, let’s say, “informed” enough to do it. You’re probably also using GitHub, which is great too. Especially since they now offer private repositories for free.

It’s not always the case, however, that you want to use a solution like GitHub, BitBucket, etc. Sometimes you’re work requirements are such that you’re code is all kept internally to your work network and you need to set up your own remotes. Here is how you do it.

On the server that will host your repos you will need to create a directory to contain them all, create the bare repository for your project then initialize the empty repo. Lets say your repository directory will live off of root and be named git.

$ mkdir /git
$ mkdir /git/my-repo.git && cd /git/my-repo.git
$ git --bare init

Your empty repository is ready to go, so go back to your workstation. Replace username and host with your username and the dns name or ip address of the remote server.

$ git remote add origin username@host:/git/my-repo.git
$ git push origin master

And that’s it. You have have a remote repository under your control.