Git is a software and be installed on different OS, such as Linux, Mac, Windows. Github is a web server which provide a tool for people to use on a website.
on Github
Create a repository Create a new file Commit (same as save) Issue (like comments) Create an organization Create branch Pull request Merge
Most of the time, you need to work on your local machine to use git. You can clone your repo from github.
make this a repo located on your local OS compare with github repo you clone
1 2 3 4
git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean
After you make some changes on your local computer, you need to save it into repo, it is not just save, it needs two steps to “save” into repo.for example, add a new line in “README”
1 2 3 4 5 6 7 8 9 10
git status On branch master Your branch is up-to-date with 'origin/master'. 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")
1
git add README.md
put this changed file to a stage to wait to be saved in the future. any changes if want to be saved should be added to this stage first!
1 2 3
git commit README.md -m "add new line under bottom" [master 37c5b60] add new line under bottom 1 file changed, 1 insertion(+)
only done this, the changed can be “saved” into repo
you can just make changes on your local, but can’t push it to others repo. You can sync from other’s repo, but just one direction, from others to your local, not from your change to others.
If you first fork others’s repo to your github, then clone your github url to your local, you can make changes and pull or push to your github. On your github you can pull request to the original repo.
about branch
show the present branch you are
1 2 3
git branch branch_newfile * master
change to other branch
1 2 3
git checkout branch_newfile Switched to branch 'branch_newfile' Your branch is up-to-date with 'origin/branch_newfile'.
If you want to see the commit history on local
1 2 3 4 5 6 7 8 9 10 11 12 13 14
git log commit a43ab8dd9725911488d4e33f4518e9c03c8ee538 Merge: 12021a5 99e5eb0 Author: Anna X <vmnet8@gmail.com> Date: Sat Sep 7 17:06:46 2019 -0700
all
commit 12021a54f4ab8be1dad823cf428e9b57cac98e0b Merge: 9dce990 eb4ac1f Author: Anna X <vmnet8@gmail.com> Date: Sat Sep 7 16:41:52 2019 -0700
commit all changes
Make a repo on your local computer
1 2 3 4 5 6 7 8
mkdir new_repo git init Initialized empty Git repository in /home/anna/github_repo/new_repo/.git/ ll total 12 drwxrwxr-x 3 anna anna 4096 Sep 9 12:34 . drwxrwxr-x 16 anna anna 4096 Sep 9 12:34 .. drwxrwxr-x 7 anna anna 4096 Sep 9 12:34 .git
create a .git file under this dir, it means it created a repo If you want to sync to github, just login your github account, create an empty repo. Then bond the local and github repo together.