user2206911
user2206911

Reputation: 45

github commands to update only single file

I am beginner for gitHub. I have used svn before but I am not getting grip on github after going through many tutorials on the net. I have no idea about basic work flow. I created clone by using github. If I make any change in file suppose file_A then what is right step to push this file on server: I am assuming :

git status->git commit->git pull -> git push

I have doubt that it push all project files on server But i was expecting to update only file_A. Please suggest me complete command/syntax with file path.

Upvotes: 3

Views: 32291

Answers (3)

rohit
rohit

Reputation: 13

Git Commands to update files in git:

To Add Upstream: (Initially You need to do it) git remote add upstream

Save Local Changes to Temp git stash save

Updating Local From Master git pull --rebase upstream master

Apply Local changes Done earlier on latest Code taken from git master git stash apply

To Update Fork: git Status git add "Resource Name to Add to Fork" git Commit -m " Comments"

To Put these changes in Master: git Push

Then Create Pull Request from Fork

Updating Fork From Master git push origin master

Upvotes: -1

SnapShot
SnapShot

Reputation: 5544

If I could make a suggestion - you might find it easier to not focus first on Github. Instead, if you have not already, go through an online book/tutorial for git (not Github) and learn the basics of git using the command line on your local machine and without involving a remote server or service like Github. In fact you do not even have to be connected to the Internet to learn much of git. This online book is excellent and starts at the beginning and teaches you how git works. Once you are confident in the basics you can start connecting to remote machines like Github.

Upvotes: 1

Nils Werner
Nils Werner

Reputation: 36765

You are not pushing files but changes. So if you have cloned a repository with a lot of files and only changed one of them, you're only sending in the change to that one file. In your case that would be:

git clone [email protected]/some/repo .
git status                             # nothing has changed
vim file_A
vim file_B
git status                             # file_A and file_B have changed
git add file_A                         # you only want to have the changes in file_A in your commit
git commit -m "file_A something"
git status                             # file_B is still marked as changed

You can and should continue doing changes and commiting them until you're pleased with the result. Only then you should push the changes back to GitHub. This assures that everybody else cloning the repository in the meantime will not get your potientially broken work-in-progress.

git pull origin master
git push origin master

will send in all commits you made after you cloned the repository.

Upvotes: 8

Related Questions