Category Archives: Source Control

Re-apply gitignore on already pushed files

Imagine the scenario you pushed your whole project to git and you realise there is no .gitignore, all the miscellaneous, unnecessary files are already in your repo. You quickly add the .gitignore file, but nothing happens!

This is because you first need to clear your cache:

git rm -r --cached .

Now you can re-add (better to say clean) you files with the following command:

git add .

You should see many files to be removed from you instance. Now you can do your commit-push as usual.

Happy coding!

Setting up GitHub’s Personal Access Token (PAT)

When we are using multiple GitHub accounts on the same machine, they can be easily mixed up and cause errors. One solution for that is to incorporate Personal Access Token (PAT) for our repos.

First of all login to your GitHub account and select ‘Settings’ option from under your avatar:

From the left menu’s bottom side search for ‘Developer settings’:

Select ‘Personal access tokens’ option:

Click on the button ‘Generate new token’:

You might be forced to input your password and/or your token.

Input a note for the PAT, give an Expiration and select scopes:

For basic source code usage, ‘repo‘ category is enough.

From the bottom click on ‘Generate token’. The page will be redirected back to the list but on the top you will see the newly created token:

The token shown on the picture is not a real one 🙂

Now, when you are setting up your GitHub repo’s remote url use the following template:

https://GitHubUserName:PAT@github.com/RepoOwnerGithubUserName/RepoName.git

Example given:

https://Szerpentin:ghp_mynewlycreatedpat@github.com/Szerpentin/BlogDavid_PythonBasicTesting.git

SourceTree

If you are using SourceTree you can set it up under the repo’s ‘Settings’ option or clone the repo already with the PAT included url:

Happy coding!