0

Is there a way to pull a specific .gitignore from an external repository into my current project?

In this instance I would like to pull the Python .gitignore file from this Github repository but can't seem to find a way to do it.

If possible, I imagine this would be a very useful thing to learn for future projects.

Is it possible?

Mus
  • 7,290
  • 24
  • 86
  • 130
  • If you're going specifically to GitHub for one specific file, there's a GitHub-specific way to do this directly. You used the `[git]` tag instead of the `[github]` tag, though, so see [Saurabh P Bhandari's answer](https://stackoverflow.com/a/59331264/1256452). – torek Dec 14 '19 at 00:27
  • This instance relates directly to GitHub but the question relates to git in general; how can this be achieved "the Github way"? `[github]` tag added to question. – Mus Dec 14 '19 at 08:41

2 Answers2

2

In your current project, run the following commands :

# Add external repo as remote (named "upstream")
git remote add upstream https://github.com/github/gitignore.git
#                       ^         <external repo url>         ^

# Fetch the external repo
git fetch upstream

# Checkout the particular file from the remote repo
git checkout upstream/master -- Python.gitignore
#           <remote>/<branch>    <path/to/file>  

# Commit the changes in your local repo
git commit

References :

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
0

GitHub specific method (perhaps better as a separate question, but see the see-also reference below):

If you click on your own link and look at the right side of the displayed-file-content pane, you will see a row of clickable boxes labeled raw, blame, and history (followed by clickable icons). Clicking on the one labeled RAW gets you the URL https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore.

See also What do raw.githubusercontent.com URLs represent?

torek
  • 448,244
  • 59
  • 642
  • 775