Hi Bruce,
I can answer this.
"git checkout -b new-branch" is my preferred way to create new branches on the fly. It does exactly two simple things.
1. It creates a new branch at the current commit named "new-branch". (This step is equivalent to "git branch new-branch".)
2. It switches the current branch to this new one. ("git checkout new-branch")
It doesn't change any of your files/dirs. It doesn't change what you've already staged. It doesn't care what dir you're in. As a local operation, it doesn't care about your remotes. It just creates a new branch for you, ready to use. The next commits you do will go onto this branch (unless you checkout something else).
You can verify it worked by running "git branch" with no args, which will list your branches.
That's the gist of it, but I'm going to go into more detail since your questions seem to be about branches in general.
All of git's metadata, including branch and commit data is stored in the ".git" dir at the root of your repository. When you manipulate branches in any way, that is where the changes physically occur. You can treat ".git" as a black box. You should never need to go in there.
Everything outside of that ".git" dir is your "worktree", which is just the term for all of your files. This is what you edit and eventually add and commit. No special metadata here at all.
I'm going to assume you know about commits. The important details for now are that each commit points to a parent commit, forming a chain: its history. The history can branch/diverge, meaning that multiple commits can share the same parent. It can also converge: merge commits can have multiple parents. To see this for youself, run "git log --graph --all". Though, it will look pretty simple if you have no branches or merges.
With all of that out of the way, I can now tell you that a branch is just a label/reference to a commit. The commit it points to is the tip or "HEAD" of that branch. When you create a commit on a branch, all you're doing is moving that label to the next one. That label on the tip of the branch is all git needs to know to infer its whole history and where it diverged.
Git has the concept of the "current branch", which is the one that your commands will affect. You only have one current branch. So, if you run multiple "git checkout -b new-branch2" as you asked, you will create mutiple branches at the same location, but only the last one will remain the current branch. (And if any of the branches already exist with the same name, the command will fail.) "git checkout" is the way to change the current branch (and update your worktree to match).
You asked about how to upload the files in the new branch? Just push the branch. The default remote name is "origin" (check with "git remote -v"). To push the new branch run "git push origin new-branch". This will create or update a "new-branch" branch on the remote, pushing up all of its history. That is, the commit pointed to by "new-branch" and all of its parents that aren't already present in the remote. A commit is also a snapshot of the files, so by pushing the commit, you also upload the files.
I hope this helps. Feel free to ask me more questions. Also, tonight I'm planning to be at the space for Open Coding Thursday.
Best,
Robbie
--
You received this message because you are subscribed to the Google Groups "LVL1 - Louisville's Hackerspace" group.
You received this message because you are subscribed to the Google Groups "LVL1 - Louisville's Hackerspace" group.