? use git client in Ubuntu system to manipulate GitHub code

Source: Internet
Author: User
Tags git client git clone git commands

First, install git under Ubuntu
Ubuntu12.04 LTS By default is already installed Git, you can use git--version test whether install.
If not installed, use the command: sudo apt-get install git git-core installation git

Second, SSH authentication
Under Ubuntu, use SSH to connect to the Github.com SSH service with the login name [email protected] (all GitHub users share this SSH user name).

ssh-t [email protected]

Prompt after execution: Permission denied (PublicKey).
This means that we have not properly set up the public key authentication in the GitHub account.

Next, create a public/private key pair with the Ssh-keygen command under Ubuntu:

Ssh-keygen-c "[Email protected]"-F ~/.ssh/github

The contents of the ~/.ssh/github.pub public key are then copied to the Clipboard,

Gedit ~/.ssh/github.pub

The public key is a long string, note that when pasting, do not add extra spaces, line breaks, etc., otherwise in the public key authentication process because the server and the client public key mismatch, resulting in authentication failure. Finally, copy the correct public key content into GitHub's key text box and name the SSH and save it.
After the setting is successful, using terminal to access GitHub with SSH commands will display a successful authentication message and exit.

ssh-t [email protected]

Prompt after execution: Hi github! You've successfully authenticated, but GitHub does not provide shell access.
You can use GIT commands to access GitHub's code warehouse directly with these steps.

Third, submit the code to GitHub
First, create a new repo on github.com, add the appropriate. Gitignore,license to the situation, and then submit the local code to GitHub

Git pull

Get new version

git status
git add
Git commit-m "Add new Files"
git remote add origin [email Protected]:franfan/php-demo
Git push-u Origin Master

Four, git common Operation command collection:
1) Remote Warehouse related commands
Checkout warehouse: Git clone git://github.com/jquery/jquery.git

View remote repositories: Git remote-v

Add remote repository: Git remote add [name] [url]

Delete Remote repository: Git remote RM [name]

Modify remote repository: Git remote set-url--push [name] [Newurl]

Pull remote repository: git fetch [remotename] [Localbranchname]

Push remote repository: git push [remotename] [Localbranchname]

* If you want to submit a local branch test to the remote repository as the master branch of the remote repository, or as another branch called Test, as follows:

Git push Origin test:master//submit local Test branch as remote Master Branch

Git push Origin test:test//submit local test branch as remote Test branch

2) Branch (branch) operation related commands
View local branch: Git branch

View remote branch: Git branch-r (Git fetch origin first if you still can't see it)

Create local branch: Git branch [name]----Note that the new branch will not automatically switch to the current branch after it is created

Toggle Branch: Git checkout [name]

Create a new branch and immediately switch to a new branch: Git checkout-b [name]

Check out remote branch directly: Git checkout-b [name] [RemoteName]

Delete branch: The git branch-d [name]-D option removes only the branches that have joined the merge and cannot be deleted for branches that do not have a merge. If you want to forcibly delete a branch, you can use the-D option

Merge branch: git merge [name]----Merge a branch named [name] with the current branch

Delete Remote branch: git push origin:heads/[name] or GIT push origin: [name]

* Create an empty branch: (Before executing the command remember to submit your current branch of the changes, otherwise it will be forced to delete the clean without regret)

git symbolic-ref HEAD refs/heads/[name]

Rm. Git/index

Git clean-fdx

3) version (tag) operation related commands
View version: Git tag

Create version: Git tag [name]

Delete version: Git tag-d [name]

View remote version: Git tag-r

Create a remote version (local version push to remote): Git push origin [name]

Delete remote version: Git push origin:refs/tags/[name]

Merge the remote repository tag to the local: Git pull Origin--tags

Upload local tag to remote repository: Git push origin--tags

Create annotated Tag:git tag-a [name]-M ' YourMessage '

4) Sub-module (submodule) Related Operations Command
Add sub-module: $ git submodule add [url] [path]

For example, git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs

Initialize submodule: $ git submodule init----run only once when the warehouse is first checked out
Update submodule: git submodule update----need to run every time you update or switch branches
To delete a submodule: (4 steps away OH)

1) git rm--cached [path]2] Edit the ". Gitmodules" file to delete the associated configuration node of the Submodule
3) Edit the ". Git/config" file to delete the relevant configuration node of the Submodule
4) Manually delete the remaining sub-modules directory 5) Ignore some files, folders do not submit
Create a file with a name of ". Gitignore" under the repository root and write an unwanted folder name or file with one line per element, such as

Target
Bin
*.db

6) Regret medicine
Delete files that are not versioned in the current warehouse: Git clean-f

Restore the repository to the last commit state: Git reset--hard

7) Git push multiple remote repositories with one click
Edit the. git/config file for the local warehouse:

[Remote "All"]
url = [email protected]:d Ragon/test.git
url = [email protected]:d Ragon/test.git

This allows you to push all the way to multiple remote repositories with git push all

? use git client in Ubuntu system to manipulate GitHub code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.