Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I push certain files to origin/master in Git?

Tags:

git

push

I am little bit new to Git. I would like to push some files to my Git origin (remote).

What I did:

I had my master, and I created a branch to do some job. After that I merged my branch to my master. During my work, a lot of binary files and project files were changed/added locally. I would like only to add .java files which changed to remote server.

(I believe that I experimented with commits when I worked on my branch, just to check how it work.)

My master is up to date with my origin (that is what I get when I do git pull. Also I did git fetch origin. I always received (when I ran git status):

On branch master Your branch is ahead of origin/master by 12 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean`

I tried to add, commit those files, but running git status wasn't changed. I tried to do add, commit on the new branch:

On branch NewBranch nothing to commit, working directory clean

I tried to reset Head. I didn't find a solution for my problem in the Git tutorial or on Stack Overflow.

Of course I can push all files to remote origin, but I don't think it's a good solution.

Some duplicate questions that I found: How to push a single file, how to push changes made to only certain files?, and How to commit only some files?.

like image 532
Mike.R Avatar asked Sep 05 '14 15:09

Mike.R


2 Answers

I solved my problem: (I was confused with git status response because it wasn't changed when I tried to add/commit files which were already there).Thanks to linuxdan and DaveZych and Temich.

git checkout -b NewBranch

After that I deleted all unnecessary files.

git rm --cache build/web/WEB-INF/classes/doggizz/utils/\*.class

Move back to master

git checkout master

(only disadvantage that those files were deleted when I moved back to master so I copied manually project file , I tried to stash before checkout but it didn't helped)

git merge NewBranch
git push
like image 159
Mike.R Avatar answered Oct 21 '22 05:10

Mike.R


  1. Create a new branch from master
  2. git checkout master
  3. git checkout -b new_branch
  4. Checkout just the file you want from your old branch
  5. git checkout old_branch path/to/some/file
  6. repeat as necessary for additional files
  7. Commit the files to your new branch
  8. git commit -a
  9. Push new branch to origin master branch
  10. git push origin new_branch:master
like image 41
linuxdan Avatar answered Oct 21 '22 03:10

linuxdan