Simple getting started with Git for mac OS x, osgit

Source: Internet
Author: User
Tags svn update how to use git using git sourcetree

Simple getting started with Git for mac OS x, osgit

The details are as follows;

1. First, you need to know what Git is.

In short, Git is a distributed code version management tool. Similar common tools include SVN and CVS.

Concepts see; http://baike.baidu.com/subview/1531489/12032478.htm? FromId = 1531489 & from = rdtself & fr = wordsearch

2. Why use Git.

Compared with SVN and CVS, Git provides distributed code management. This does not mean that SVN and so on do not have this function, but for now, Git is more and more accepted. The future and ease of use are the benchmarks I have always chosen.

In use, the biggest advantages of SVN are;
Only one branch code is available! Log local! It is easier to merge code! More secure! The directory is more concise!

A simple explanation;

Only one branch code is available!
Kids shoes who have used svn must know that when we want to develop a new function, add a new version, or modify a complicated bug, we usually need to copy the entire code to a local directory, then add it to the svn server for code management.
Different from Git, Git can create many branches, and each branch is independent. When we need to modify the code, commit only modifies the local repository. If SourceTree is used, we will find that the Git Flow function in the toolbar is well prepared.

Log local!
Svn logs are stored on the server. To view the modification records, you must be able to connect to the remote server and have permissions. Different from Git, Git's modification records for the local repository are stored locally for easy access.

It is easier to merge code!
Because Git supports local unlimited Branches, when we create multiple branches locally for different purposes (modify, add, and explore ), merging a copy of code is obviously easier than merging a bunch of Project copies with svn.

More secure!
Unlike SVN, the Git commit command only updates the code of the local repository. You must use the push function to submit data to the master remote warehouse or other remote branch warehouse. Although a process has been added, it can prevent the risk of major problems caused by the merger at will.

The directory is more concise!
In the root directory of the local Git repository, there is only one. git file, which contains all the management information. As we all know, SVN has a heart-wrapper. svn in each subdirectory. This issue needs to be considered when you need to modify file conflicts. It must be a simple file.

3. How to install Git to MAC OS X
Two methods are introduced here;
1. Use Git command-line
Ii. Use the GUI tool SourceTree, which is very powerful and convenient

Before installation, let's talk about how to create a server like Git and SVN. They can all create their own version management servers. For individuals and small teams, it may be more appropriate to use managed servers,
Github and Bitbucket are common examples. Here I will introduce Bitbucket. Github is open-source because there is no personal free repository, so here I select Bitbucket. In addition, the personal repository page of Bitbucket is now basically in Chinese. The registration process is also relatively simple.
For more information, see the link; https://bitbucket.org/

The following describes how to use Command-line.
1, download Git installer, address; http://git-scm.com/downloads
2. Download the package and double-click. pkg to install it.
3. Open the terminal and run the git -- version command to check the installation version. If yes, the installation is successful.
/* If the following 4.5 commands have been created using Bitbucket, they will automatically contain */
4. Create a global user name
Git config -- global user. name "FIRST_NAME LAST_NAME"
5. Create a global mailbox
Git config-global user. email "MY_NAME@example.com"
6. If you do not want to enter the password every time you connect to the remote warehouse, enter the following command:
Git credential-osxkeychain
------> Wait
Git config -- global credential. helper osxkeychain
# Set git to use the osxkeychain credential helper
Now Git is installed.

2. We will not introduce SourceTree here. The initial installation is similar to that of SVN.

4. How to Use Git
Two methods are also introduced here.
1. Use command
Ii. Use SourceTree

First, we will introduce the first method; Command line

When using the command line of the terminal, we must first have some knowledge about the linux Command Line. In actual use, it is often used less often. Here we only introduce some necessary information.
Reference; http://www.renfei.org/blog/mac-os-x-terminal-101.html

Basic linux commands;
Sudo-s get absolute User Permissions
Cd xxx enters the xxx directory
Ls (-a/-A) displays all files in the current path (hidden)
Pwd displays the current absolute path
Mkdir xxx create folder xxx
Man xxx view xxx command Manual

Next, we will introduce the meaning of Git basic commands;
Clone and clone remote Repository
Init initialization Repository
Remote connection to remote warehouse
Pull pulls new data from the remote warehouse drop-down list
Push: uploads new or modified files from the local repository to the remote repository.
Add to add a file or modify a file. Before using commit or push
Log information submitted by the current Warehouse
Status current repository version status
Commit to current Warehouse
Branch commands and related addition, deletion, and query operations
Checkout uses the last version of the remote repository to completely overwrite the content of the current repository/select branch
Comparison of diff versions
Merge Version Content
See the link for details; https://confluence.atlassian.com/display/BITBUCKET/Bitbucket+Documentation+Home

To use Git, we certainly need a remote repository. Assume that we have created a Bitbucket account (used to create a remote repository ).
The method for creating a remote repository is described here.
1. Use the Git command to create
2. Create on Bitbucket

First, use Git command line

Initialization
Git init
--------->
Copy repository address from Bitbucket
--------->
Add the source to remote repository address with the alias "origin"
Git remote add origin https: // myAccountName@bitbucket.org/myAccountName/myRepositoryName. git

Second, create a remote repository on the Bitbucket
After registration, follow the prompts to create it. This is very simple... Do not repeat it.
For more information, see https://confluence.atlassian.com/display/bitbucket/bitbucket?documentation=home的bitbucket 101.

--------- The above is the initial creation -------------- gorgeous split line --------------- The following is the operating version library -------------------

With the remote repository Repostiory, we should add code or other files.

Here we will introduce two types;
1. Use command-line
Ii. Use SourceTree

First, use command-line
After connecting to the remote repository in the local directory (clone command), use the following method to operate the file.

Git add xxx add or modify the xxx File
------------------>
Git commit-m "adding repo instructions" Submit the xxx file to the local repository version;-m "XXXX"; Submit the log
------------------>
Git push-u origin master submits xxx and log to the master branch of the remote Repository origin (the alias of the remote Repository just created)

Second, use SourceTree
Similar to svn, the specific process is;
Add ---- add file to index -----> commit ------ submit to local warehouse ------> push -------- upload to remote warehouse --------->

Then add, modify, and delete the files in the repository.

Ps: Remember to use the git pull command every time you operate on the local repository instead of creating another branch to update the remote repository to the local to prevent conflicts. This is similar to SVN update.

First, we will introduce it here. In fact, it is basically similar to SVN command line tools and gui tools.
The main difference in actual use is that the distributed development mode is different.

Thank you for your attention ~

Segmentation line --------------------------------- The following describes Git Branch -------------------------------------------------

Branch is a Branch. Compared with SVN, Git has the perfect distributed management capability. Each local Repository, that is, the Repository, is equivalent to a local version server. On this basis, we can perform many Branches for different
Type development. Branch's directory uniformity makes it easy to manage, including merge.

1. First introduce Branch under SourceTree,
Here we provide a detailed blog link for your reference. The illustrations are illustrated in detail and I will not repeat it.
Reference: http://www.takobear.tw/12/post/2014/02/bear-git-flow-sourcetreegit-flow.html

2. Use command-line to create a branch

To be continued ......

Split line --------------------------------- tips -----------------------------------------------

1. Git Stash command
Speaking of branches, using Git to develop more complex projects I think there will certainly be multiple local projects. If we have a temporary urgent important task and need to switch to another branch, then we need to commit the current content.
However, we can use the Stash command if I don't want to submit the modified content to the repository for any other reasons.
$ Git stash
This command means that the content of the current workspace is put in a temporary area, which means that it is invalid to use the git status or add commit command.
But we protected the site well. Next, you can checkout to other branch jobs.

After you return, you need to reply to the site. Here, we will briefly describe a working mechanism of the stash command.
When the stash command is used, the content of the current work area will be pushed into a stack queue. Yes, it is the same as navigationController.
Suppose we want to reply to the site. There are two options: pop and apply.

Pop, as the name suggests, the current temporary content disappears from the stack queue. apply is the same as objectAtIndex, and the temporary content still exists in the queue.

When multiple branches are stash, the following two commands are used;

Git stash list: displays all the backups saved in the Git stack. You can use this list to determine where to recover from.
Git stash clear: clears the Git stack. In this case, you can use gitg and other graphical tools to find out which nodes of the original stash have disappeared.

Ps: Remember to use the git status command a lot. It's just like a poor memory. Git helps us to take more notes to prevent errors.

2. Let Git ignore annoying files that do not want to be tracked
1. You can set the files to be ignored in the entire Git repository.
$ Git config-global core. excludesfile ~ /. Gitignore_global
$ Vim ~ /. Gitignore_global

Set the file to be ignored in the. gitignore_global file. For example, add the following
# Mac OS X
*. DS_Store

# Xcode
*. Pbxuser
*. Mode1v3
*. Mode2v3
*. Perspectivev3
*. Xcuserstate
Project. xcworkspace/
Xcuserdata/

# Git
. Gitingore
. Gitingore. swp

And save it. If you enter git status, the system still prompts that an unexpected file is being tracked. Need to clear
$ Git rm -- cache xxx is the file to be ignored

Okay, no more annoying files.

2. You can set ignore files for a directory separately.
To the directory where you want to ignore the file,
$ Vim. gitignore
Add the name of the rule
Save and exit.

For the naming rules for ignoring files, see the link:
Http://bdxnote.blog.163.com/blog/static/844423520124153051409/

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.