Branches
satya - 4/11/2018, 9:48:51 AM
Commits and branches
satya - 4/11/2018, 9:49:46 AM
The checkout
satya - 4/11/2018, 9:50:06 AM
How do I work with multiple branches in Git?
How do I work with multiple branches in Git?
satya - 4/11/2018, 9:54:07 AM
You can use this to find out how many branches are there on local
git branch
will produce
*b1 //current
b2
b3
satya - 4/11/2018, 9:54:33 AM
You can create multiple branches
git branch b2
git branch b3
satya - 4/11/2018, 9:54:57 AM
You can switch to branch b3
git checkout b3
satya - 4/11/2018, 10:29:58 AM
A summary!
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
satya - 4/11/2018, 10:30:54 AM
Git seen as Operations on a directory!
Git seen as Operations on a directory!
satya - 4/16/2018, 10:58:56 AM
Merge commit
Creates a new merged auto commit
has two commits as parents of this commit
satya - 4/16/2018, 10:59:30 AM
See this commit on to master from iss53
satya - 4/16/2018, 10:59:55 AM
See the new commit on master
satya - 4/16/2018, 11:02:21 AM
This is where remote branching is discussed
satya - 4/16/2018, 11:26:14 AM
Tracking branches is explained here as well
satya - 4/16/2018, 11:27:38 AM
Local link: Understand checkout, fetch, pull, and clone here
Local link: Understand checkout, fetch, pull, and clone here
satya - 4/16/2018, 12:06:22 PM
So what did I learn about branching so far?
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
satya - 4/16/2018, 12:06:41 PM
Here is a discussion on PUSH on SOF
satya - 4/20/2018, 1:43:47 PM
Take a close look at branches again: you missed something before
satya - 4/20/2018, 1:47:28 PM
Branches START on previous commit points
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.
satya - 4/20/2018, 1:50:11 PM
When you switch to a new branch
//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
satya - 4/20/2018, 1:51:08 PM
So the additional work
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
satya - 4/20/2018, 2:09:15 PM
So what is the relationship between a working directory and branches?
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!!!
satya - 4/20/2018, 2:36:53 PM
Merge has a prerequisite - It is an action between 2 commits!
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!
satya - 4/20/2018, 2:54:26 PM
Not really...here is the real fact from the docs on merge
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.
satya - 4/20/2018, 2:54:40 PM
So it is allowed, but with a lot of caution...
So it is allowed, but with a lot of caution...