---
title: Git commands I wish I knew early
description: >-
  Best git commands I have used in my decade long coding career. Ignoring local files to prevent
  unwanted changes from being pushed and many more.
url: https://expiredqueues.com/git-commands-i-wish-i-knew-early/
date: '2018-05-10T04:15:42.000Z'
image: https://expiredqueues.com/images/og/git-commands-i-wish-i-knew-early-c218d022.jpg
---

Written in May 2018. Details may have aged; read with the date in mind.

Developer Tools posts git

# Git commands I wish I knew early

10 May 2018 By Adrian 2 min read

It has been a little more than a decade since I started coding.

Started my career in this industry as a web designer, then moved on to become a front-end developer with savvy HTML and CSS tricks. Later around 2012 started renaming all resume and online profiles to claim to be a JavaScript developer - with Vanilla JS, AngularJS blah.. blah.. blah... and then now a full-stack developer. Heck!!!

One simple thing has remained consistent even though I have moved on from position to position, shifting focus from design to programming, changing primary language from Photoshop to PHP to JavaScript - is [the tools I use to work](https://expiredqueues.com/books/the-pragmatic-programmer/).

Git and Github, in particular, have played a major role in my career. Along with its useful features - it brought many nightmares as well.

Committing passwords, secret keys, unwanted changes etc. - I have had my fair share of embarrassments! I wish I knew more than \`git push\` and \`git pull\`.

## Git commands I wish I knew early

1. Ignore changes from tracked files, temporarily
2. Undo local changes
3. Remove file from remote Git repository but keep locally
4. Remove git tracking entirely from a project

### 1. Temporarily ignore changes from tracked files

Tell Git to stop tracking changes

```bash
git update-index --assume-unchanged filename.ext
```

and to start tracking again -

```bash
git update-index --no-assume-unchanged filename.ext
```

### 2. Undo All Local Changes

Please note the dot, meaning reset everything to last pull state in the current directory.

```bash
 git checkout .
```

If you just wish to reset one file, replace the dot with filename.ext

### 3. Remove file from remote Git repository but keep locally

You sometimes join the project in the middle of dev activities. The file is already on the remote repository - let us say '.env' or my 'secret.keys'.

Following command to the rescue:

```bash
git rm --cached filename.ext
```

Or if you have to remove an entire directory, e.g. \`fakedata/\` then:

```bash
git rm --cached -r directoryName
```

Above, "-r" means, recursively. 

### 4. Remove git tracking entirely from a project

Let's say you cloned a git repo, some boilerplate or starter template but it has all the tracking pointed towards its author git repository.

When you need to start fresh and remove the old git tracking and initialize new git repo, do following:

```bash
rm -rf .git
```

Example above, "-rf" means recursively force the command. Git stores all tracking data inside hidden ".git" directory. All we did here is delete that directory.

Now if you wish to start a fresh git repo on this same directory - "git init" should do.

## Tips

Take a look at StackOverflow for top voted questions.

<https://stackoverflow.com/questions/tagged/git?sort=votes&pageSize=15>

### You might be interested in:

- [A better ls on macOS: use eza, but not as an alias](https://expiredqueues.com/better-ls-macos-eza/) - the other command I run a few hundred times a day.
- [All Code hosting on Github](https://expiredqueues.com/github-hosting/) - when this blog's own projects moved to Git.

[Previously On the verge of MNC life](https://expiredqueues.com/on-the-verge-of-mnc-life/) [Next How to stop zoom in on input focus on mobile devices](https://expiredqueues.com/stop-zoom-in-on-input-focus-on-mobile-devices/)

## Structured data

```json
{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "Git commands I wish I knew early",
  "datePublished": "2018-05-10T04:15:42.000Z",
  "dateModified": "2018-05-10T04:15:42.000Z",
  "author": {
    "@type": "Person",
    "name": "Adrian",
    "url": "https://expiredqueues.com/about/"
  },
  "publisher": {
    "@type": "Person",
    "name": "Adrian"
  },
  "mainEntityOfPage": "https://expiredqueues.com/git-commands-i-wish-i-knew-early/",
  "keywords": "posts, git, github, tips-tricks, tools",
  "articleSection": "Developer Tools"
}
```
