BentCoder
BentCoder

Reputation: 12740

Pushing only one file to GIT

Before I do mistake, I need to know what I'm about to do is correct. I did some researches but still want make sure because I'm new to GIT and scared of messing whole project. Yes there are a lot of examples but I'm confused. That's all.

I have 3 files in local GIT and just want to commit one of them and push it to live GIT. So are these steps correct?

WHAT I THINK I SHOULD DO !!!

sudo git add web/js/admin/design.js
sudo git commit -m 'Bug fix'
sudo git push origin sprint-6

GIT STATUS:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   src/Hello/AdminBundle/Controller/DesignController.php
    modified:   web/js/admin/design.js

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    src/Hello/AdminBundle/Utility/DesignPublisher.php

no changes added to commit (use "git add" and/or "git commit -a")

Upvotes: 10

Views: 81284

Answers (4)

Eric Onah
Eric Onah

Reputation: 11

There's no single git command to push a single file to a remote repo as of the time of this reply rather you just have to commit the file you want to push to github alone with git add <filename> followed by git commit -m "<commit msg>" <filename> then git push <remote> <branch>

Upvotes: 0

Sumit Verma
Sumit Verma

Reputation: 179

If we want to commit and push only a single file out of all modified/new files, we need to commit that particular file first. Here are the steps to commit and push a single file:

  1. Commit single file:

    git commit -m 'your comment' path/to/your/file.txt
    
  2. Push file to git:

    git push remote-name current-branch-name
    

Upvotes: 7

Zacrath
Zacrath

Reputation: 556

It looks correct to me but if you want to be sure you can run git push with the --dry-run option (-n for short).

If you make a mistake you can revert the commit and try again.

Upvotes: 2

Ren&#233; H&#246;hle
Ren&#233; H&#246;hle

Reputation: 27295

You commit only files that are added to the repository. So if you need only one file then add only the one file.

git add src/Hello/AdminBundle/Controller/DesignController.php

And then commit it. Files that are untracked are not included in the repo. There you have to add it first.

Upvotes: 10

Related Questions