3.8 KiB
Executable File
Git Basics
Create a new repository
$ touch README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git remote add origin https://github.com/example/rhymes.git
$ git push -u origin master
Getting project from a repository
$ git clone https://github.com/example/rhymes.git
Tracking New Files
Add file contents to the index.
$ git add README.md
Show the working tree status.
$ git status
Record changes to the repository.
$ git commit -m "first commit"
Push an existing repository and Update remote refs along with associated objects $ git push -u origin master
Remove files from the working tree and from the index
$ git rm file_name
Fetch from and integrate with another repository or a local branch
$ git pull
$ git pull origin master
Managing branches
To create a new branch
$ git branch branch_name
If you know branch lists, you run
$ git branch
$ git branch -a
If you are currently on your branch
$ git checkout you_branch_name
Deleting branch
$ git branch -d branch_name
Merging branches
Before using "git merge", make sure the correct local branch is checked out.
$ git checkout master
$ git merge remote_branch
View current remotes
$ git remote -v
Example:
origin https://github.com/OWNER/REPOSITORY.git (fetch)
origin https://github.com/OWNER/REPOSITORY.git (push)
Adding Remote Repositories
$ git remote add other_user_name https://github.com/example/rhymes.git
Example:
$ git remote add pb https://github.com/paulboone/ticgit
origin https://github.com/OWNER/REPOSITORY.git (fetch)
origin https://github.com/OWNER/REPOSITORY.git (push)
pb https://github.com/paulboone/ticgit (fetch)
pb https://github.com/paulboone/ticgit (push)
Fetch a copy of other user's work.
$ git fetch user_name
Removing a remote
If you want to know other user's works,
$ git remote add other_user_name https://github.com/example/rhymes.git
and then you can see works
Merge
Review all the branches (both local and remote).
$ git branch -a
Check out a local copy of other_user work and review it.
$ git remote add name http://branch/name.git
$ git fetch name
$ git checkout -b remote_branch name/remote_branch
$ git diff master remote_branch
$ git log -1 -p
Checkout master and merge Bobs changes in.
$ git checkout master
$ git merge remote_branch
example,
From https://git.com/Alice/rhymes de64fd9..95029d3 master -> John/master
- [new branch] test -> John/test
- [new branch] test_change -> John/phyo_change
Rebase forked repository Or update forked repository
- Add the remote of original repository, example call it "upstream":
$git remote add upstream https://git.autoleum.com/Sai/fserver-fe
- Fetch all the branches of that remote into remote-tracking branches,such as upstream/master:
$git fetch upstream
- checkout master branch
$git checkout master
- merge branches
$ git merge upstream/master
- Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch
$git rebase upstream/master
- Push your forked master, need to use '-f' for first time push
$git push -f origin master
Create Patch From Diff
$git diff > mypatch.patch $git apply mypatch.patch
Store Git Credential
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: [type your username]
Password: [type your password]
[several days later]
$ git push http://example.com/repo.git
[your credentials are used automatically]
Install GOGS repo From npm
$npm install --save git+https://git.mokkon.com/sainw/mokkon-reactjs.git#v1.1.0