Git Usage in Ubuntu

Install

$ sudo apt-get install git

Sign Up on github.com

Click here to sign up on github.com.

Create SSH Key

$ ssh-keygen -t rsa -C "youremail@example.com"

id_rsa and id_rsa.pub will be created under /home/.ssh folder while id_ras is private key and id_rsa.pub is public key. Sign in github, and enter personal settings->SSH and GPG Keys. Click New SSH Key. Copy the content in id_rsa.pub and paste here.

Usage of git

Create repository

$ git init

Check the status of local repository

$ git status

Add changes to repository

$ git add file1name file2name ...

Add all changed files

$ git add .

Commit changes

$ git commit -m "comments come here"

Add remote repository

$ git remote add origin git@github.com:XXXX/XXXXXX.git

Use the command

$ git remote -v

to check the remote repository that you just added.

Push

$ git push -u origin master

while origin is the name of remote repository and master is the name of local repository.

When the remote repository is empty, add -u parameter in the command, otherwise not.

Pull

$ git push origin master

Clone

$ git clone git@github.com:XXX/nameRepo.git

A new folder that has the same name as repository, like nameRepo here will be created and all the files will be cloned in this folder.

If you want to clone the repository to another folder, add a destination path after this command, like this

$ git clone git@github.com:XXX/XXXXX.git destination

Note that no Chinese characters in repository path and do not use share folders between VMware and host in your repository path!!!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

13 − 2 =

5 + 5 =