RajSanpui
RajSanpui

Reputation: 12104

How to add a file to a particular branch in git?

I am doing some sample test with git, before i add my actual stuff.

Here is what i do:

enter code here
1) Create an empty git repository

$ mkdir git_trial2
$ cd git_trial2
$ git init (Creates a .git directory inside this)
$ cg-branch-add branch1 (Create a branch1 inside this git)
$ touch File1
$ echo "This is a test" >> File1

Now i want to add File1 to branch1. How to do this?

Upvotes: 0

Views: 187

Answers (2)

TomH
TomH

Reputation: 9260

Well we really need to know what your mysterious cg-branch-add command does, but assuming that it just adds a branch with git branch then you will need to start by switching to that branch:

git checkout branch1

then add the file:

git add File1

and commit it:

git commit

Upvotes: 1

stijn
stijn

Reputation: 35921

you can just

git checkout branch1
git add File1
git commit -am "added File1"
git checkout other_branch

and File1 will only be in branch1

Upvotes: 1

Related Questions