Common Git Commands

Source: Internet
Author: User
Tags hosting web hosting web hosting services git commands

Github/bitbucket

GitHub is a git-based code hosting platform, where paid users can build private warehouses, and our general free users can only use public repositories, which means the code is open.

GitHub website address:https://github.com/. Then you can create the warehouse (free users can only build public warehouses)

https://bitbucket.org

BitBucket is a Web site that provides web hosting services for projects that use mercurial and GIT version control systems. BitBucket offers both a free account and a commercial payment scheme. Business accounts can use an unlimited number of private repositories (free accounts up to 5 users) as of September 2010, and if users can invite 3 friends to register for BitBucket, then up to 8 users can be served [1]. Private repositories are not displayed on individual pages, and if the user has only a private repository, the site will show that no repository has been created until the user has created a public repository. BitBucket is written using the Django Web application framework under Python.

1, create a New Repository, fill in the name after create, there will be some warehouse configuration information, this is a simple git tutorial.

Github Installation
    • Download git OSX version
    • Download git Windows edition
    • Download the git Linux version
Configure Git

1. Create locallyssh key;

$ ssh---"[email protected]"   

Later, [email protected] instead of the email you registered on GitHub, you will be asked to confirm the path and enter the password, and we'll use the default return line. Successful words will be generated in the ~/ next .ssh folder, go in, open id_rsa.pub , copy inside key .

2, GitHub, enter account Settings (accounts configuration), choose SSH keys,add ssh key on the left, paste the key generated on your computer.

In order to verify success, enter it under GIT bash:

-T [email protected].  COM  

If it is the first time will prompt whether continue, enter Yes will see: You ' ve successfully authenticated, but GitHub does not provide shell access. This means that you have successfully connected to GitHub.

3. Upload your local warehouse to GitHub, and before that you need to set up username and email, as GitHub will record them each time it commits.

--Global user." Your name "--global user." [Email protected] "        

Go to the repository you want to upload, right-click Git Bash, add remote address:

$ git Remote add origin [email protected].  COM:yourName/yourrepo.  git       

The following yourname and Yourrepo indicate that you re-github user name and the newly created warehouse, added after the addition of the. git, open config, here will be a remote "origin" content, this is just added to the long-range address, You can also modify config directly to configure the remote address.

4, create a new folder, terminal into the directory, execute  git init the creation of a new Git repository.

Check out the warehouse

Execute the following command to create a cloned version of the local repository:

/Path/to/     

If this is the repository on the remote server, your command will look like this:

git clone [email protected]:/path/to/repository    
Work Flow

Your local repository consists of three "trees" maintained by git. The first one is yours 工作目录 , it holds the actual file; the second is 暂存区(Index) that it's like a cache area that temporarily saves your changes, HEAD and finally, it points to the result of your last commit.

You can make changes (add them to staging area) by using the following command:
git add <filename>
git add *
This is the first step in the Git basic workflow, using the following command to actually commit the changes:
git commit -m "代码提交信息"
Now, your changes have been submitted to HEAD, but not to your remote repository.

Push Changes

Your changes are now in the HEAD of the local repository. Execute the following command to commit the changes to the remote repository:
git push origin master
You can replace master with any branch you want to push.

If you have not cloned an existing repository and want to connect your warehouse to a remote server, you can add it using the following command:
git remote add origin <server>
So you can push your changes to the server you added.

Branch

Branches are used to insulate the development of features. When you create a warehouse,master is the "default" branch. Develop on other branches, and then merge them onto the main branch when you are finished.

1. Create a branch called "feature_x" and Switch to the past:
git checkout -b feature_x
2. Switch back to the main branch:
git checkout master
3, then delete the new branch:
git branch -d feature_x
4. Unless you push the branch to the remote repository, the branch is not visible to others :
git push origin <branch>

Update and Merge

1, update your local warehouse to the latest changes, to do:
git pull
2. To get (fetch) in your working directory and Merge (merge) the remote changes.
to merge other branches into your current branch (for example, Master), execute:
git merge <branch>
3, in both cases, Git will try to automatically merge the changes. Unfortunately, this may not be successful every time, and there may be conflicts (conflicts). You will need to modify these files to manually merge these conflicts (conflicts). After you've changed, you'll need to execute the following commands to mark them as merged successfully:
git add <filename>
4. Before merging the changes, you can use the following command to preview the differences:
git diff <source_branch> <target_branch>

label

Creating labels for software releases is recommended. This concept is already in existence and is also available in SVN. You can create a label called 1.0.0 by executing the following command:
git tag 1.0.0 1b2e1d63ff
1b2e1d63ff is the first 10 characters of the commit ID you want to tag. You can get the commit ID using the following command:
git log
You can also use a little less commit ID before several, as long as it's pointing is unique.

Replace local changes

1. If you make a mistake, you can replace the local change with the following command:
git checkout -- <filename>
This command replaces the files in your working directory with the latest content in the HEAD. Changes that have been added to staging area and new files are not affected.

2, if you want to discard all your local changes and submissions, you can get the latest version history on the server and point your host branch to it:
git fetch origin
git reset --hard origin/master

Practical Tips

Built-in graphical git:
gitk
Color git output:
git config color.ui true
When the history is displayed, only one row is displayed for each submitted message:
git config format.pretty oneline
Interactively add files to staging area:
git add -i

Links and ResourcesGraphical Client
    • GITX (L) (OSX, open source software)
    • Tower (OSX)
    • Source Tree (OSX, free)
    • GitHub for Mac (OSX, free)
    • Gitbox (OSX, App Store)
Guides and Manuals
    • Git Community Reference Book
    • Professional Git
    • Think like Git.
    • GitHub Help
    • Diagram Git
related articles
    • A concise guide to Github: http://rogerdudler.github.io/git-guide/index.zh.html
    • How to use github:http://www.yangzhiping.com/tech/github.html efficiently


Data Source:Github Simple Tutorial rnu7ncck/git-guide.htm

Http://rogerdudler.github.io/git-guide/index.zh.html

Https://zh.wikipedia.org/wiki/Bitbucket

Common Git Commands

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.