Expired Queues
Published since 2009 Core-CSS.net → CSSJunction.com → Expired Queues Web development

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

Developer Toolspostsgit

Git commands I wish I knew early

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.

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

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

and to start tracking again -

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.

 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:

git rm --cached filename.ext

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

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:

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: