Branches

How do I work with multiple branches in Git?

Search for: How do I work with multiple branches in Git?

Beginers guide to branches


git branch

will produce

*b1 //current
b2
b3

git branch b2
git branch b3

git checkout b3

Git works on root directories that has a .git in there (although at a unit level it works on files)

Lets think about it that way, operations on the file system for a collection of files

No remote nothing, just local, for now...

Your work is labeled across multiple branches

each branch can have as many checkpoints as you like (commits)

You can switch between these branches

working directory will take you back (or sync) to the branch you wish. This is a nice way to switch between multiple books

This is another way to look at a DIRECTORY

Swap books! so to say

Git seen as Operations on a directory!

Basic merging doc

Creates a new merged auto commit

has two commits as parents of this commit

This is where remote branching is discussed

Tracking branches is explained here as well

Local link: Understand checkout, fetch, pull, and clone here

Here is more on rebasing

There is a repo

repo is local

a remote repo is just another repo, with a name (ref) attached to it

a local repo has many branches that you can switch to any one of them through checkout. Each branch has many commit points.

Local branches and remote branches are disconnected and different

You can fetch remote branches to make them available on the local machine but they are distinct from local branches

Remote branches are read only

You can merge remote branch content with a merge command to a local branch

You can use checkout to create a matching/tracking local branch that is a copy of the remote branch

You can do a pull to fetch and merge a tracked branch

A clone will setup matching and tracked remote branches on the local box

Tracked branches are still separate

when you push the local commits are transported to the related server branch commits

push does not merge as I understand, but the master branch on the server now has the latest commits that were not there before

Here is a discussion on PUSH on SOF

So "somebranch" starts on commit "c2"

when you do your work, you are always sitting on a branch.

when do some work and "create" a new branch, the new branch will ignore the uncommitted work and base itself on previously committed check point. The new work is not part of the newly created branch

the newly created branch is not switched to yet. If you were to switch now, the everything in the directory seem to stay the same!!

This is because the commit points at this moment are identical. And the additional uncommitted work stays so the switch appears seamless.


//Say on branch1:b1
current code = b1-cur-commit + additional work

//swtich to branch 2: b2

//From the working directory
Remove b1-cur-commit
retain additional work
Bring in b2-home-commit

You can commit before switching and make it part of the current branch

Or

You can switch and make it part of the new branch

working directory = cur-committed-branch-code + new code

Branch = committed-set-aside-code

A checkout may mean take me to the new branch, but that doesn't mean drop everything I have!!! Only drop the last committed parts, and leave the pending changes (additions) intact.

So if a file has been modified but not committed, and the same file exists in the new branch, the file in the new branch will not replace the old file! If that is your intention then you need to commit that file before switching!!!

So a merge is invalid or disallowed if there are uncommitted files in the working directory.

Those have to be committed first before a merge can take place.

Committed files "travel" to their branches with them. While uncommitted files stay in the working directory.

In a way commit gives the set of files "flight", so to say!

Warning: Running git merge with non-trivial uncommitted changes is discouraged: while possible, it may leave you in a state that is hard to back out of in the case of a conflict.

So it is allowed, but with a lot of caution...