Question

If I am on branch b-one and I run git commit -m "init commit" and then git checkout -b b-two, does the commit carry to the new branch? More generally, are commits branch specific? Or when you commit, are you just committing on your local machine and can access that commit from any branch?

Was it helpful?

Solution

  1. Does the commit carry to the new branch? Yes, but only if it is a new branch. Other existing branches will not have your commit in its history log.

The git checkout command lets you navigate between the branches created by git branch. Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch. Think of it as a way to select which line of development you’re working on.

  1. More generally, are commits branch specific? No, history are shared.
  2. Or when you commit, are you just committing on your local machine ? Yes, before pushed, no one else knows about your commit.
  3. Can access that commit from any branch? No. What does 'access' mean ? if you mean commit history or changed code, only branches created off a branch with your committed changes have your commit history.

It is more interesting when you switch branch with un-committed changes: Please read http://www.gitguys.com/topics/switching-branches-without-committing/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top