Thursday, April 20, 2017

Git - Commit local update to Github

1. For example, I want to update the README.md file on my local drive:
# README

This is the finished work from Getting Started with Rails on
http://guides.rubyonrails.org/getting_started.html

A User can access to the blog by either as registered user or as a guest.
A guest can:
* View the article list of the blog
* View the text (details) of each article
* Add a comment

A registered user with user name and password can also do the functions of a guest with these additional functions:
* Add a new article
* Edit an article
* Destroy (delete) an article
* Destroy a comment

2. We can see which files are in the staging area using the status command:
$ git status
 
3. Git is incredibly good at making branches, which are effectively copies of a repository where we can make (possibly experimental) changes without modifying the parent files.
$ git checkout -b modify-README
M    README.md
Switched to a new branch 'modify-README'

$ git branch
  master
* modify-README 

4. Edit the file: README.md and save the file.

5. Check the status of Git:
$ git status
On branch modify-README
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:   README.md

no changes added to commit (use "git add" and/or "git commit -a") 

6. Commit the changes:
$ git commit -a -m "Improve the README file"
[modify-README 28c7a64] Improve the README file
 1 file changed, 19 insertions(+), 24 deletions(-)
 rewrite README.md (96%)
7. Merge to branch 'master'
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git merge modify-README
Updating bf0f534..28c7a64
Fast-forward
 README.md | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)
8. (Optional) After you’ve merged in the changes, you can tidy up your branches by deleting the topic branch using git branch -d if you’re done with it:
$ git branch -d modify-README
Deleted branch modify-README (was 28c7a64).
9. Push the changes to Github. The command line will prompt for Github username and password:
$ git push
...
Username for 'https://github.com': jimmy2046
Password for 'https://jimmy2046@github.com':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 573 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/jimmy2046/gettingstarttedwithrails
   bf0f534..28c7a64  master -> master
10. Go to your Github site (for example: https://github.com/jimmy2046/gettingstarttedwithrails) to check the changes are made on Github.

No comments:

Post a Comment

How to kill an abandoned process in Linux/Unix

I remembered it, then I forgot, then I remembered it, and then I forgot again. In case of a Linux/Unit process hang, I have to figure out ...