问题
I haven't done much branching work in git and branching so excuse the noob nature of this.
I'm going to start working on a feature (say 'user oauth') that I want to work in isolation and merge in at a later point. Ideally, I will be merging this into the master branch at a later point. Obviously, I'd like to do in a separate branch. Is it general practice to just do a branch in my local instance or should I fork the repo and create a branch in the new separate folder structure. In my mind, the latter seems better in case I just want to wipe out the branch, I can just delete this other folder structure?
thx
edit 1 per ryan
git clone git@github.com:xxx/xxx.git
git branch test-feature-branch
edit 2 wow, thx for information. It's possible that this will be a second application. Is there a way I can clone it and then essentially push it as a new repository to new github?
回答1:
The whole point of git cloning and branches is that making separate repos is not necessary. A fork is really just another name for a clone and as such, you can make branches for multiple features at the same time within your local clone, picking and choosing which ones to push to the remote and/or merge into other branches (or discard).
See the answers to this question for more details: git branch, fork, fetch, merge, rebase and clone, what are the differences?
回答2:
You cannot fork a git project. You can clone a existing one. Clone-ing is basically creating a new project starting from another one.
I would not do this when adding new functionality unless i want 2 different applications.
If adding functionally that you want it merged back into the main with git you can do:
git checkout -b secondBranch
--this will create the branch "secondBranch" and also put you in that branch immediately. The next commit will be on this secondBranch.
If you want to delete it just do
git branch -d secondBranch
or if you decide to merge it, switch to the master /main branch and merge secondBranch into it.
git branch master
--will swith you to master
git merge secondBranch
--at this point you will be in the master branch with the changes from secondBranch merged into the master
回答3:
It's definitely general practice to just create a branch in your local instance. When you're done, simply merge it into e.g. your master branch and push master to origin.
来源:https://stackoverflow.com/questions/9742159/should-i-do-a-git-fork-then-branch-or-just-a-git-branch