Search code examples
gitcg

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?


Solution

  • 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