Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing only one file to GIT

Tags:

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")
like image 583
BentCoder Avatar asked Jul 05 '14 12:07

BentCoder


People also ask

Can we push only one file in git?

Push Single file to git For this, you have to run specific command to push the only single file to git. Above all commands are related to push the only single file to git but sometimes we want to push only two files to git in a single commit.

How do I push a single file to a GitHub repository?

On GitHub.com, navigate to the main page of the repository. Above the list of files, using the Add file drop-down, click Upload files. Drag and drop the file or folder you'd like to upload to your repository onto the file tree.

How do I commit a single file in git?

To add and commit files to a Git repository Create your new files or edit existing files in your local project directory. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

How do I push a specific folder into a git repository?

Git Push Recap In the command line, go to the root directory where your local files are. Optionally initialize the local directory (git init). Add the your file changes (git add) and commit your changes (git commit). Finally, push your changes of the local file or repository to GitHub (git push).


1 Answers

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.

like image 91
René Höhle Avatar answered Sep 21 '22 05:09

René Höhle