15 minutes to learn how to use Git and remote code library

Source: Internet
Author: User
Tags how to use git

Git is a great but complex source code management system. It supports complex tasks, but is often considered too complex and not suitable for simple daily work. Let's be honest: Git is complicated and we should not pretend it is not. But I will still try to teach you how to work with (my) Basic Git and remote code libraries within 15 minutes. I will demonstrate the following steps, which usually help me build projects on one or more machines.

  1. Create a remote empty code library (on BitBucket)
  2. Add a project to the local code library
  3. Develop new functions on the branch
  4. A) Retain new features or B) discard them
  5. Maybe, return to an earlier time point
  6. Push local code library to remote code library
  7. Obtain the remote code library on another machine
Install Git on most * nix systems (Linux and OS X). Git has been installed. By sending the following command, you can update it to the latest development version through Git itself (not recommended ).
Git clone https://github.com/git/git
On Windows, you can download the Git installer here. If you really need installation programs from other systems, the Mac OS X Installation File is here, and the Linux operation guide is here. Many people prefer to use Github to create a remote code library. I personally prefer BitBucket because it provides an unrestricted private code library, which is what I need most. You can convert the following commands to Github. These processes are the same. Go to www.bitbucket.org and register an account. After logging on, click "create" at the top of the page. Follow the instructions in the form and check the private code library. You don't want others to peek at the source code of your Facebook killer application, right. Now you can leave the BitBucket. We already have everything you need. Before setting Git to work with Git, we need to make a one-time configuration. In order for Git to track who made the changes, we need to set your username. I strongly recommend that you use the same user name and email address as registering a BitBucket account. Send these commands to replace "your_username" and "your_email@domain.com" (note the quotation marks ):
Git config -- global user. name "your_username" git config -- global user. email your_email@domain.com
We will also set the default value of push to 'simple '. To understand what this means, read the default values (not required) about push I posted earlier ). Send this command:
Git config -- global push. default simple
We have all set up. You do not need to repeat these configurations on your machine, but do not forget them if you work on another machine. If you forget to make the initial configuration, Git won't allow you to submit anything, which will bother you. Create a local code library as an example. We pretend that we have a website (which is not technical) stored in the 'my _ site' folder in the 'workspace 'folder on our machine. Go to the root folder of your site in the command line. On OS X and Linux:
Cd ~ /Workspace/my_site/
On Windows:
Cdc: \ workspace \ my_site
First, we need to tell Git that this folder is the project we need to track. So we sent this command to initialize a new local Git code library.
Git init
Git will create a hidden folder named. git in the my_site folder, which is your local code library. To load (Stage) files, we now need to run Git. We need to load (stage) All project files. Send:
Git add.
The last "." symbol indicates "all files, folders, and subfolders ". If we only want to add specific files to the source code control, we can specify them:
Git add my_file, my_other_file
Now, we want to submit a file that has been loaded (staged. Read "add a time point where your file is in a recoverable state ". When we submit our files, there are always meaningful comments that describe their current status. I have always used "initial commit" as the comment for the first commit.
Git commit-m "initial commit"
That's it. Now you can roll back to this submission status at any time. If you need to check the status and submission of your currently loaded (staged) and unloaded (unstaged) files, you can ask about the git status:
Git status
Creating a branch is an independent version of your code. It is independent of your main branch. By default, each time you submit a file to Git, it will be stored in the "master (master)" branch. Now, you want to add a feature to the project, but you want to be able to roll back to the current version to prevent errors, or you decide to discard this feature. This is the time to create a branch. Create and switch to the new branch at the same time, send:
Git checkout-B new_feature
Alternatively, you can create a branch and then manually switch it, as shown in the following figure:
Git branch new_featuregit checkout new_feature
To view all the branches under your current project, send this:
Git branch
Now you can do whatever you want on your project: at any time, you can go back to the status before you create the branch. Note that you can have multiple branches at the same time, or even create another branch from one branch.

Git details: click here
Git: click here

Recommended reading:

Fedora downloads Git through Http Proxy

Install Git on Ubuntu Server

Create a Git repository on the server (Ubuntu)

Git simple tutorial in Linux (taking Android as an example)

Git authoritative guide PDF

  • 1
  • 2
  • Next Page

Related Article

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.