Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github commands to update only single file

Tags:

github

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.

like image 447
user2206911 Avatar asked Jan 14 '23 00:01

user2206911


2 Answers

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.

like image 55
Nils Werner Avatar answered Jan 27 '23 06:01

Nils Werner


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.

like image 39
SnapShot Avatar answered Jan 27 '23 05:01

SnapShot