How to ignore vendor directory in git for Go projects

You accidentally added your vendor directory to git in your Go project.   Now when you run git status you see all these modified files under the vendor directory.

Here is a quick command you can use to ignore these changes

First change to your project directory then run this command

git status | perl -ne ‘/(vendor.+go)/ && system “git update-index –assume-unchanged $1\n”;’

This will take each file mentioned in the status that is in your vendor directory and execute a git command against it to

tell git to stop tracking it.

In the long run, you should probably not add your vendor directory to your VCS.  For git, you should create a .gitignore file under your project directory and add vendor/ in that file.

Here is a complete .gitignore file that you can use for your Go projects from here:

# Folders

# Architecture specific extensions/prefixes




# Output of the go coverage tool, specifically when used with LiteIDE

# external packages folder


You may also like...