These 2 days, I did research about github. Let me write down my learning summary.
1. What is github?
It is a version control platform. It can record the changes of a project, and can help developers to collaboratively develop one project together.
It is actually a directory. And it is the unit where a project exists.
Branch is like a copy of a project. You want to modify a project based on an original one, but you don’t want to affect the original one. At this time, make a new branch of it, and modify based on the branch.
It is actually downloading a project. Download a project to your own laptop. After that, you can modify the project as you want.
You want to contribute to someone’s project, you can click fork. In this way, this project will exist in your own github, and you can modify it as you want. After you done with that, do pull request to the project owner.
Following are some useful commands I summarized:
make current directory working repository
initialize existing directory
>git clone https://github.com/libgit2/libgit2
or clone to a new directory
>git clone https://github.com/libgit2/libgit2 mylibgit
change file, and push it to your own remote github
>git add [file_name]
>git add . //this is to add all changed files
>git add A //this is to add all changed files
>git commit -m “commit message” //commit, save the change
>git push origin master //origin is the remote name, master is the branch you are using.
add remote to master
>git remote add origin https://github.com/user/repo.git
In local master, do merge from branch2
>git merge branch2
check current git account
>git config user.name
>git config –list
create a new branch
>git checkout -b [name_of_your_new_branch]
>git checkout [name_of_branch]
get local repository updated
>git pull origin master
add a new branch
>git branch [new_branch_name]
change to a branch
>git checkout [branch_name]
git push origin master
This pushes to origin from local master to origin master branch
git push origin local-name:remote-name
This pushes on origin, local-branch to remote-branch.
Normally when I do a push in git I do something like git push origin master, which really means push from the local branch named master to the remote branch named master. If you want to push to a remote branch with a different name than your local branch, separate the local and remote names with a colon:
git push origin [local-commit]:remote-branch
push local commit to remote branch in origin
git push origin [local-commit]:remote-branch -f
This one will force push, regardless if there is conflict between local and remote branch
git remote –v
show all remote repos. After this command, we can see where origin is from