To understand the solution, you have to understand what is the purpose of .gitignore and maven.
Why .gitignore?
Git is used to track changes made to each files in your project. However there can be other files in your project which do not require tracking.For example, .metadata which is created by eclipse to keep information about workspace settings or preferences. Since you are not going to modify it and also it is not required for your project, this metadata file should be placed in .gitignore list . For more information check .gitignore.
Thus .gitignore does not serve your purpose of linking custom external JAR to your project.
Why Maven?
Maven is a build management tool. There are various common problems and activities we face during developing an application.
- Your application may require multiple external jars. For example, lets say spring framework which requires its own jar files to compile and run project.
- Another problem is that supplying dependencies to these jar files.For example, spring jar might depend on other jar files and its your responsibility to make sure you provide all dependent jar files as well.
Maven helps easing this process. Along with that maven helps to build,publish and deploy your project.
Maven uses XML file called pom.xml contains the configuration settings for a project build. Generally we define the project dependencies (Ex: dependent jar files for a project), maven plugins to execute and project description /version etc. Here is the link for further reading about maven.
To achieve your requirement you have to provide details about external jars in the pom.xml and push your project along with pom.xml. When you pull the repository in another machine, just run maven commands it will automatically download all the required jars in your local machine.