11

I am new to git and hope using it properly.

git init
git add .      // added the whole directory
git commit -m "initial stage"
git checkout -b "version1"
git branch

  master
* version1

Now i want to add some new files in the directory

cp /path/to/file/admin.php /path/to/git/folder/.

These files should include only on version1 branch but it is also including in the master branch

git add admin.php
git status
On branch version1
Untracked files:
(use "git add <file>..." to include in what will be committed)
admin.php

git checkout master
git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
admin.php

The question is how can i add files only on specific branch??

Thanks

prabhu
  • 301
  • 2
  • 3
  • 10
  • 2
    That file does not exist on *either* branch; it's "untracked", in git terminology. Until you `git add` *and* `git commit` it will continue to not exist anywhere in the repository, only in your working directory. You need to start with some [git basics](http://git-scm.com/book/en/Getting-Started-Git-Basics)... (*Technically, `git add` will save it to something temporary, but it won't become permanent until the `git commit` step.) – torek Jul 17 '14 at 14:40
  • @torek your comment is exact an answer. So why not answer? – RomanHotsiy Jul 17 '14 at 14:48
  • http://stackoverflow.com/a/2569513/3802077, what @torek said but with more info and more specific – user3802077 Jul 17 '14 at 14:51
  • @RomanGotsiy: Mostly because a full answer would take too long, and be redundant with other existing SO answers and the Pro Git book. The question betrays a fundamental misunderstanding of git. – torek Jul 17 '14 at 15:45

2 Answers2

28

In order to add files in specific branch follow the below instructions :

To create custom branch

git branch branchname

To switch into custom branch

git checkout branchname

To initialize in the custom branch

git init

To add files in the custom branch

git add file name

To commit the changes made in the custom branch

git commit -m "your message"

To make changes in your GitHub repo

git push

Hope you get clear cut idea.

Thank you.

nawazlj
  • 779
  • 8
  • 18
1

Sometimes when you use

git add fileName

you get this error

The following paths are ignored by one of your .gitignore files: fileName

In order to still add it, go to your .gitignore and comment the line associated with that file adding #,

#fileName

Then you will be able to add, commit, and push.

Robert Houghton
  • 1,202
  • 16
  • 28
Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145