Search code examples
githubgithub-for-mac

Github for mac - pushing selected files only


I'm new to github and currently only starting off using github for mac.

I have taken a clone of my client's website and made some development changes locally. Note: I'm literally working with the files in the directory I sync with.

I want to push only one small change as the rest is still under development. Is it possible to push only the one file?


Solution

  • Git pushes deal with commits, not files. You'll need to create a commit that contains your selected changes. This is one area where Git's index is really handy.

    Let's say you've modified two files, foo and bar.

    If you want to commit only the changes to foo, using the command line you can do

    git add foo
    git commit
    

    This will create a new commit updating foo, but bar's changes will remain only in your working copy. You can now push the new commit.

    It's been a while since I've used the graphical GitHub tools, and I've only used them on Windows, but I believe the way to commit only certain files is to check or uncheck the box beside each file before you commit. You can see these checkboxes in their documentation:

    You can go even further. If some of the changes in bar should be part of a commit, but not all of them, you can do something like git add --patch, which will break your changes up into chunks and prompt you for the ones to add to the index (these are the ones that will be included when you commit).

    On GitHub for Mac you can do this too:

    Select one or more lines to commit by clicking on the line numbers in the gutter. In the latest release, you can select a block of changes at a time. Hover over the right hand side of the line numbers to get a preview of what will be selected, and click to select.

    See the documentation for git-add for details.