GIT - branches, what is branch?

萝らか妹 提交于 2019-12-23 06:29:45

问题


I am new to GIT. I want to create a new branch: I have 3 files inside that repository.

If I create a new branch, do I have to copy that files; Or are they copied automatically if I create a new branch?

When I want work on the branch, do I have to switch to that branch inside GIT, before I start to work (opening that files)? Thank you very much for your help


回答1:


I want to create a new branch

# checkout new branch based upon the current branch 
git checkout -b <new branch name>

If I create a new branch, do I have to copy that files; Or are they copied automatically if I create a new branch?

The new branch is a FULL copy to the current branch.
In order to understand why you need to know what is branch in git.


What is branch in GIT?

A branch in Git is simply a lightweight movable pointer to commit.
Here is a very short and simple post about it

In other words:

Branch in git is simply a pointer to a commit.
As you can see in the image below (taken from the post mentioned above), all the branches are pointing to commit B + the delta which was added to them.

When you create branch git creates a file and writing the commit id to this file.

When I want work on the branch, do I have to switch to that branch inside GIT, before I start to work (opening that files)?

This is what's the checkout -b does - switch you to the new branch



来源:https://stackoverflow.com/questions/34921623/git-branches-what-is-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!