Programmer
Programmer

Reputation: 133

How do you use Git? I would like to push a file back into the Github repo?

I am currently collaborating with a few others on a large Java project, and have cloned the repository to work on it from my home PC. I went ahead and changed 2 files within the whole directory/subdirectory structure of this gigantic project, and would like to just push those two files I've edited back into the repository.

Is there a command I can use in order to accomplish this? Thanks.

Upvotes: 0

Views: 782

Answers (4)

Michael Durrant
Michael Durrant

Reputation: 96454

git pull origin master - make sure your master branch is up to date with the latest changes in the remote repository defined by origin (frequently github).

git status - show files that you've modified in the branch you are in.

git add . - add the files you've modified to your current branch.

git commit - save changed files to your current branch.

git push origin master - send the changed files in the master branch to the remote repository.

Upvotes: 0

simont
simont

Reputation: 72527

Once you've git cloned the repository, and made changes to files, you can use git status to see what files have changed.

Select changes to commit using git add. When you've selected ('staged') all the changes you wish to commit, git commit them. That will commit to your local repository.

To push the commits to github, use git push.

If you're new to git, I'd very highly recommend you at least browse through the Pro Git book. It's got some good diagrams and explanations for a whole bunch of git topics; I found it very useful. In particular, for this question, look at the 'Recording changes to the repository' and 'Working with remotes' sections.

The StackOverflow Git FAQ / Wiki also has some neat information for common questions; some of those are related to yours, such as this one.

Edit: As an aside, about this part of your question:

... just push those two files I've edited...

Git thinks in terms of commits, not in terms of files. You can't push a subset of files in your repository, because a commit encompasses the entire repository at the time of the commit. git push and other network-type git commands, though, are pretty darn good at working out what they should be sending to the remote repositories. Don't worry, even if the repository is large, if you've changed two source files, a git push won't push every single file back to the remote repository.

Upvotes: 0

Andrew T Finnell
Andrew T Finnell

Reputation: 13628

If you added new files make sure to add them with git add

git commit -a -m "Commit message"

git push

To get any new changes they made ahead of yours you'll need to pull first

git pull

then fix any merge conflicts and commit the merge.

Upvotes: 2

ThiefMaster
ThiefMaster

Reputation: 318468

Assuming you committed your change and it's in a branch that already exists on the server, you can simply use git push.

Upvotes: 0

Related Questions