Git Tutorial
Creating a Branch in git
Lets learn how to create a local branch in the repository
It is time to make our hello world more expressive. Since it may take some time, it is best to move these changes into a new branch to isolate them from master branch changes.
Step1:Create a branch
Let us name our new branch «style».
RUN:
git checkout -b style
git status
Note: git checkout -b <branch name>
is a shortcut for git branch <branch name>
followed by a git checkout <branch name>
.
Note that the git status
command reports that you are in the style branch.
Step2:Add style.css file
RUN:
touch lib/style.css
FILE: lib/style.css
h1 {
color: red;
}
RUN:
git add lib/style.css
git commit -m "Added css stylesheet"
Step3:Change the main page
Update the hello.html
file, to use style.css.
FILE: lib/hello.html
<!-- Author: kwikl3arn ([email protected]) -->
<html>
<head>
<link type="text/css" rel="stylesheet" media="all" href="style.css" />
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
RUN:
git add lib/hello.html
git commit -m "Hello uses style.css"
Step4:Change index.html
Update the index.html
file, so it uses style.css
FILE: index.html
<html>
<head>
<link type="text/css" rel="stylesheet" media="all" href="lib/style.css" />
</head>
<body>
<iframe src="lib/hello.html" width="200" height="200" />
</body>
</html>
RUN:
git add index.html
git commit -m "Updated index.html"
Next
Now we have a new branch named style with three new commits. The next lesson will show how to navigate and switch between branches.