Simple Git Commands

1. configure up git account
$ git config –global “John Doe”
$ git config –global

2. add a remote git
$ git remote add [local_git_name] [remote_git_url]

3. fetch the remote repository
$ git fetch [remote_git_name]

step 2, 3 can be done use clone
$ git clone [remote_git_url] [local_git_name]

4. create a branch named newfeature to work on
$ git branch newfeature
$ git checkout newfeature

or $ git checkout -b newfeature

5. add  all changes
$ git add -A

6. commit changes
$ git commit -m ‘comments’

7. change to master and update master
$ git checkout master
$ git pull

8. merge newfeature with master
$ git merge newfeature

9. push to origin
$ git push origin master

10. resolve conflicts
$ git diff

11. change remote git uri
$ git remote set-url [new_uri]

12. create a new git repository
$ git init

13. add a remote git
$ git remote add [remote_uri]

14. check all remote in repository
$ git remote -v

15. see git logs
$ git log

16. want undo commits
$ git checkout [commit-log-hash-num] .   (this . is necessary for all trees commit)

17. rollback to a point
$ git reset –hard [commit-log-hash-num]
$ git push -f [origin] [branch]

Reference :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s