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:
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# external packages folder
vendor/