Asked  7 Months ago    Answers:  5   Viewed   33 times

I keep hearing people say they're forking code in Git. Git "fork" sounds suspiciously like Git "clone" plus some (meaningless) psychological willingness to forgo future merges. There is no fork command in Git, right?

GitHub makes forks a little more real by stapling correspondence onto it. That is, you press the fork button and later, when you press the pull request button, the system is smart enough to email the owner. Hence, it's a little bit of a dance around repository ownership and permissions.

Yes/No? Any angst over GitHub extending Git in this direction? Or any rumors of Git absorbing the functionality?

 Answers

95

Fork, in the GitHub context, doesn't extend Git.
It only allows clone on the server side.

When you clone a GitHub repository on your local workstation, you cannot contribute back to the upstream repository unless you are explicitly declared as "contributor". That's because your clone is a separate instance of that project. If you want to contribute to the project, you can use forking to do it, in the following way:

  • clone that GitHub repository on your GitHub account (that is the "fork" part, a clone on the server side)
  • contribute commits to that GitHub repository (it is in your own GitHub account, so you have every right to push to it)
  • signal any interesting contribution back to the original GitHub repository (that is the "pull request" part by way of the changes you made on your own GitHub repository)

Check also "Collaborative GitHub Workflow".

If you want to keep a link with the original repository (also called upstream), you need to add a remote referring that original repository.
See "What is the difference between origin and upstream on GitHub?"

fork and upstream

And with Git 2.20 (Q4 2018) and more, fetching from fork is more efficient, with delta islands.

Tuesday, June 1, 2021
 
Sujith
answered 7 Months ago
65

Submodules are indeed a good fit, as your repo will only record a gitlink (special entry mode 160000) to record the commit of the submodule repo you are using.

Don't forget that this submodule is a git repo of its own, which means:

  • you can make commits in it (see "true nature of submodules")
  • you can make it follow the latest commits of branch (see "git submodule update")
  • you can add remotes to it (like a remote to the original repo you have forked, in order to fetch updates from said original repo, see "What is the difference between origin and upstream in github")
Wednesday, August 4, 2021
 
twk
answered 4 Months ago
twk
97

Since the node_modules directory is already tracked as part of the repository, the .gitignore rule will not apply to it.

You need to untrack the directory from git using

git rm -r --cached node_modules
git commit -m "removing node_modules"

You can run the above 2 in git-bash.

After this, the .gitignore rule will ignore the directory away.

Note that this will remove the directory node_modules from your other repos once you pull the changes in. Only the original repo where you made that commit will still have the node_modules folder there.

Saturday, August 7, 2021
 
LunaLoveDove
answered 4 Months ago
61

I am trying to omit conflicts in gitignore file

Then don't version the final .gitignore file itself: generate it on demand.

Keep your .gitignore files separates, but add a content filter driver (a smudge script), which will:

  • detect the content of each .gitignore.xxx files
  • concatenate their content to the actual .gitignore (which is not added to git, and remains a private file)

enter image description here

Sunday, October 10, 2021
 
job
answered 2 Months ago
job
11

You could use the GitHub API for Repositories to get a specific repo

GET /repos/:owner/:repo

(you can use a curl call from command line)

The JSON answer will include a "fork" field: value true or false.

Saturday, November 13, 2021
 
Stepan Yakovenko
answered 3 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share