Source: Git and GitHub usage summary under Linux
1 building git and GitHub environments under Linux
First step: Install git and use the command "sudo apt-get install git"
Step two: Create a GitHub account on GitHub
Step three: Generate SSH key, use the command "ssh-keygen-t rsa-c" [email protected] "", Your_email is your email
Fourth step: Go back to GitHub, enter account Settings, the left choice ssh keys,add ssh key,title casually fill, paste Key. Key is
~/.ssh/id_rsa.pub content.
Fifth step: Test SSH key is successful, use the command "ssh-t [email protected]", if appear you ' ve successfully authenticated, but GitHub does not provide shell Access. This means that you have successfully connected to GitHub.
Sixth step: Configure git configuration files, username and email
git config--global user.name "your name"//Configure user name
git config--global user.email "your Email"//Configure Email
2 using Git to upload locally to GitHub
Step one: Go to the directory where you want to upload the file enter the command "Git init"
Step two: Create a local repository origin, using the command "Git remote add origin [email protected]:yourname/yourrepo.git"
Youname is your github username, Yourrepo is the repository you want to upload to GitHub, which you add on GitHub.
The third step: for example, you want to add a file xxx to the local repository, using the command "git add xxx", you can use "git Add." Automatically determine which files to add
Then add this to the local repository, using the command "Git commit-m" to explain this commit ""
Finally, submit the local repository origin to the remote GitHub repository using the command "Git push Origin master"
3 cloning projects from GitHub to local
Step one: Go to a warehouse in GitHub and copy the "HTTPS clone url" to the right
Step two: Go back to the directory you want to store, use the command "Git clone https://github.com/chenguolin/scrapy.git", the red URL is just an example
Step three: If the local version is not up-to-date, you can use the command "Git fetch origin", Origin is the local repository
Fourth Step: Merge the updated content into the local branch, you can use the command "git merge Origin/master"
If you do not want to manually merge, then you can use: Git pull < local repository > master//This command can be pulled to the latest version and automatically merged
4 GitHub's branch management
Create
1 Create a local branch: GIT branch < new branch name >
2 Synchronizing a local branch to GitHub: Git push < local repository name > < new branch name >
3 Switch to the newly established branch: Git checkout < new branch name >
4 Add a new remote end to your branch: Git remote add < remote End name > < address >
5 View the current warehouse has several branches: Git branch
Delete
1 Delete a branch from the Local: git branch-d < branch name >
2 Sync to github Delete this branch: git push < local repository name >: <github-Side Branch >
5 Common errors
1 If an error is error:repository not found.fatal:The remote end hung up unexpectedly is the wrong URL link for your origin, it could be a creation error or this [Emai L protected]:xxx/new-project.git URL specified incorrectly. Re-create.
Summary of Git and GitHub usage methods under Linux