Mus
Mus

Reputation: 7530

How can I pull a single file from an external repository into my current project?

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?

Upvotes: 0

Views: 1017

Answers (2)

Saurabh P Bhandari
Saurabh P Bhandari

Reputation: 6742

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 :

Upvotes: 2

torek
torek

Reputation: 487755

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?

Upvotes: 0

Related Questions