Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add the file on the specific branch in git

Tags:

git

github

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

like image 756
prabhu Avatar asked Jul 17 '14 14:07

prabhu


2 Answers

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.

like image 109
nawazlj Avatar answered Oct 27 '22 20:10

nawazlj


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.

like image 23
Tiago Martins Peres Avatar answered Oct 27 '22 20:10

Tiago Martins Peres