Mac is powered by git

Source: Internet
Author: User
Tags file copy python script

One, create a git account
1. Create a git account on the machine server that is used as the server. We can add them through the System preferences->accounts. Here I add a git administrator account, Administrator is not required, here just for convenience.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/78/0C/wKiom1Z0x6iBbEAbAAEZqZCjQSM914.png "title=" 0_ 13206534514ssk.png "alt=" Wkiom1z0x6ibbeabaaezqzcjqsm914.png "/>

2, set remote access
Logout your current account, log in with your Git account, and in System preferences->sharing, tick: Web sharing and Remote logig.

Second, download and install Gitosis
1,mac Snow by default, Git and Python have been installed for us, and you can use the following command to view its version information:

thingingdemacbook-air:~ git$ python--version
Python 2.7.6
thingingdemacbook-air:~ git$ git--version
git version 2.3.2 (Apple Git-55)


2, download gitosis by command "Git clone git://eagain.net/gitosis.git"

thingingdemacbook-air:~ git$ git clone git://eagain.net/gitosis.git
Cloning into gitosis
Remote:counting objects:614, done.
Remote:compressing objects:100% (183/183), done.
Remote:total 614 (Delta 434), reused 594 (Delta 422)
Receiving objects:100% (614/614), 93.82 KiB | KIB/S, done.
Resolving deltas:100% (434/434), done.

If this doesn't work:
Cloning into ' gitosis ' ...
Fatal:unable to connect to Eagain.net:
EAGAIN.NET[0:208.78.102.120]: Errno=connection refused
You can clone the Gitosis package from the following location:
git clone https://github.com/res0nat0r/gitosis.git
Cloning into ' gitosis ' ...
Remote:counting objects:727, done.
Remote:compressing objects:100% (216/216), done.
Remote:total 727 (Delta 510), reused 701 (Delta 495)
Receiving objects:100% (727/727), 111.73 KiB | KIB/S, done.
Resolving deltas:100% (510/510), done.


3. Go to the Gitosis directory and use the command "sudo python setup.py install" to execute the Python script installation gitosis.

thingingdemacbook-air:~ git$ CD gitosis/
Thingingdemacbook-air:gitosis git$ sudo python setup.py install


Third, make SSH RSA public key
1, go back to the client machine and make the SSH public key. Here I use another account on the same machine as the client. If the machine as a client is not the same as the machine for the server, it is also a type of process: make the public key and place it in the/tmp directory of the service. Just on the same machine, we can operate two accounts simultaneously by turning on another terminal and using SU to switch to a local account.

thingingdemacbook-air:~ git$ su thinging

Password:
bash-3.2$ CD ~
bash-3.2$ ssh-keygen-t RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/USERS/LOCAL_ACCOUNT/.SSH/ID_RSA):
Enter passphrase (empty for no passphrase):
Enter same Passphrase again:
Your identification has been saved In/users/local_account/.ssh/id_rsa.
Your public key has been saved in/users/local_account/.ssh/id_rsa.pub.

Thingingdemacbook-air:git thinging$ CD. SSH
Thingingdemacbook-air:git thinging$ ls

Id_rsa id_rsa.pub
Thingingdemacbook-air:git thinging$ CP id_rsa.pub/tmp/yourame.pub


In the above command, first through the SU switch to the local account (only valid on the same machine), then into the local account home directory, using ssh-keygen-t RSA to generate ID_RSA.PUB, and finally put the file copy to/tmp/yo Urname.pub, so the GIT account can access the Yourname.pub, renamed here to make it easier to identify multiple clients in Git.

Four, initialize gitosis with SSH public key
1, whether you are in that way (mail, USB, etc.) copy yourname.pub to the server/tmp/yourname.pub. The following process is the same, login to the server machine's git account, into the previously mentioned Gitosis directory, to do the following initialization Gitosis, after the initialization is completed, will be in the GIT home under the repositories directory created.

Thingingdemacbook-air:gitosis git$ sudo-h-u git gitosis-init </tmp/yourname.pub
Initialized Empty Git repository in/users/git/repositories/gitosis-admin.git/
reinitialized existing Git repository in/users/git/repositories/gitosis-admin.git/

In this case, the client will be treated as a trusted account, so there will be records in the Git home directory, and the file Authorized_keys content is similar to yourname.pub.


In this case, the client will be treated as a trusted account, so there will be records in the Git home directory, and the file Authorized_keys content is similar to yourname.pub.
thingingdemacbook-air:~ git$ CD ~
thingingdemacbook-air:~ git$ CD. SSH
THINGINGDEMACBOOK-AIR:.SSH git$ ls
Authorized_keys

We need to change authorizd_keys slightly, open it with a text editor, delete the "command=" Gitosis-serve yourname ", no-port-forwarding,no-x11-forwarding, No-agent-forwarding,no-pty "This line:
Yourname:.ssh git$ VI Authorized_keys


We then give the post-update a writable permission so that the client can commit the changes.
Yourname:gitosis git$ sudo chmod 755/users/git/repositories//gitosis-admin.git/hooks/post-update
Password:
hingingdemacbook-air:~ git$ CD ~
thingingdemacbook-air:~ git$ CD repositories/
Thingingdemacbook-air:~repositories git$ ls
Gitosis-admin.git
Thingingdemacbook-air:~repositories git$

As you can see in the above command, Gitosis is also given as a repository, we can checkout in other accounts, then configure management of Gitosis, and so on, without using the server's Git account.

The last step is to modify the path of the GIT account.
Thingingdemacbook-air:gitosis git$ Touch ~/.BASHRC
Thingingdemacbook-air:gitosis git$ echo path=/usr/local/bin:/usr/local/git/bin:\ $PATH >. BASHRC
Thingingdemacbook-air:gitosis git$ Echo Export PATH >> BASHRC
Thingingdemacbook-air:gitosis git$ Cat. BASHRC
Path=/usr/local/bin:/usr/local/git/bin: $PATH
Export PATH

At this point, the configuration of the server is complete.

Five, client Configuration
1, back to the local account, first change the local git configuration by entering the following command in Terminal:
Thingingdemacbook-air:git thinging$ git config--global user.name "Yourgitname"
Thingingdemacbook-air:git thinging$ git config--global user.email "[Email protected]"


2, the test server is connected correctly, the 192.168.1.104 is replaced with the name of your service or server address.
Thingingdemacbook-air:git thinging$ ssh [email protected]

Last Login:mon 7 13:11:38 from 192.168.1.1043, then exit, return to client

In the local clone server warehouse, take Gitosis-admin.git as an example:
Thingingdemacbook-air:git thinging$ git clone [email protected]:repositories/gitosis-admin/users/thinging/git

Cloning into Gitosis-admin
Remote:counting Objects:5, done.
Remote:compressing objects:100% (5/5), done.
Remote:total 5 (Delta 0), reused 5 (Delta 0)
Receiving objects:100% (5/5), done.
bash-3.2$ ls
Desktop Installapp Music Sites
Documents Library Pictures Gitosis-admin
Downloads Movies Public
bash-3.2$ git

As you can see in the output above, we have successfully gitosis-admin the clone server to the local repository.

4, in the local management gitosis-admin:
To enter the Gitosis-admin directory, let's look at its directory structure: The gitosis.conf file is a configuration file that defines which users can access which repositories, and we can modify this configuration; Keydir is where the SSH public key resides.
Thingingdemacbook-air:git thinging$ CD gitosis-admin/
Thingingdemacbook-air:git thinging$ ls
Gitosis.conf Keydir
Thingingdemacbook-air:git thinging$ CD keydir/
Thingingdemacbook-air:git thinging$ ls
Yourname.pub

We only need to add the SSH public key generated by the other client to the Keydir directory and configure the repository that these users can access in the gitosis.conf file (the user name is the same as the SH public key name placed under Keydir, which is why we want to modify the SSH public key name in the previous section). Then commit the changes to the server, so that other client side access to the server's code warehouse.


Sixth: Add code to the warehouse

1. Add code to the warehouse and add a jiankemall code here

2. Enter GIT status to view local changes

Changes to be committed:
(use "Git reset HEAD <file> ..." to Unstage)

New File:1.2jiankemall/jiankemall/genneral/jkwebengine/jkhelper/jkhelper.h
New File:1.2jiankemall/jiankemall/genneral/jkwebengine/jkhelper/jkstringhelper.h
New FILE:1.2JIANKEMALL/JIANKEMALL/GENNERAL/JKWEBENGINE/JKHELPER/JKSTRINGHELPER.M
New File:1.2jiankemall/jiankemall/genneral/jkwebengine/jkhelper/nsstring+jkhelper.h
New FILE:1.2JIANKEMALL/JIANKEMALL/GENNERAL/JKWEBENGINE/JKHELPER/NSSTRING+JKHELPER.M
New File:1.2jiankemall/jiankemall/genneral/jkwebengine/jksignhelper.h
New FILE:1.2JIANKEMALL/JIANKEMALL/GENNERAL/JKWEBENGINE/JKSIGNHELPER.M

Changes not staged for commit:
(use "git add <file> ..." To update what would be committed)
(use "Git checkout--<file> ..." to discard changes in working directory)

modified:1.2 New Jiankemall/jiankemall.xcworkspace/xcshareddata/jiankemall.xccheckout
modified:1.2 New jiankemall/jiankemall.xcworkspace/xcuserdata/thinging.xcuserdatad/ Userinterfacestate.xcuserstate
modified:1.2 New JIANKEMALL/JIANKEMALL/GENERAL/JKWEBENGINE/HELPER/JKSIGNHELPER.M
modified:1.2 New Jiankemall/jiankemall/sections/personalcenter/checklogisticsviewcontroller.xib
modified:1.2jiankemall/. Ds_store
Modified:1.2jiankemall/jiankemall.xcodeproj/project.pbxproj
Modified:1.2jiankemall/jiankemall.xcworkspace/xcuserdata/thinging.xcuserdatad/userinterfacestate.xcuserstate
modified:1.2jiankemall/jiankemall/. Ds_store
Modified:1.2jiankemall/jiankemall/genneral/jkwebengine/jkhelper/jkstringhelper.h
Modified:1.2jiankemall/jiankemall/genneral/jkwebengine/jkhelper/jkstringhelper.m
Modified:1.2jiankemall/jiankemall/genneral/jkwebengine/jkhelper/nsstring+jkhelper.h
Modified:1.2jiankemall/jiankemall/genneral/jkwebengine/jkhelper/nsstring+jkhelper.m
Modified:1.2jiankemall/jiankemall/genneral/jkwebengine/jksignhelper.h
MODIFIED:1.2JIANKEMALL/JIANKEMALL/GENNERAL/JKWEBENGINE/JKSIGNHELPER.M
Modified:1.2jiankemall/jiankemall/genneral/jkwebengine/jkwebengine.m
modified:jiankemall/. Ds_store
Modified:jiankemall/jiankemall.xcworkspace/xcshareddata/jiankemall.xccheckout

untracked files:
(use "git add <file> ..." to include in what'll be committed)

. Ds_store
1.2jiankemall/jiankemall.xcworkspace/xcshareddata/
jiankemall/pods/pods.xcodeproj/xcuserdata/thinging.xcuserdatad/
jiankemall/jiankemall.xcodeproj/xcuserdata/thinging.xcuserdatad/
Jiankemall/jiankemall.xcworkspace/xcuserdata/thinging.xcuserdatad


untracked files The following file is a file that has not been submitted.


3.sudo git add-a or sudo git add *//Added to pause zone


4. Submit the code to the local repository

sudo git commit-m ' Jiankemall '//-m later represents the comment at the time of submission. This better be more detailed about the better. After the mistake can come back to see which developer's mistake, as well as his modified ideas.


5, sudo git pull Origin master

Then, before committing to the server, we need to pull the warehouse code from the server to local comparison. There is no conflict (different developers modify the same file as a conflict)

Conflict resolution refer to Links

http://blog.csdn.net/u012150179/article/details/14047183


If the following error is reported:

FATAL:COULDN ' t find remote ref Master
Fatal:the remote end hung up unexpectedly
Because no one has submitted the code, the first time you have to directly push the code up.

6,sudo git push Origin master

Put the final code in the warehouse and replace the code inside the warehouse.


Seventh: Production above will open branches to complete the development of code, here also by the way branch creation

1 Viewing remote branches

$ git branch-a

    1. Master

    2. Remotes/origin/head-Origin/master

2 Viewing local branches

$git Branch

    1. Master


3 Creating a Branch

$ git branch test1

$ git Branch

    1. Master

    2. Test1


The line surface is to push the branch to the remote branch

$ GIT push origin test1

//$ git push Origin test1:master//submit local Test branch as the remote Master Branch , this is the same as the above operation
$ GIT push origin test1:test1//submit local TEST1 branch as remote Test1 Branch


4 Switching branches to test

$ git branch

    1. * Master

    2. Test1

$ git checkout test1

Switched to branch ' test '

    1. $ git Branch

    2. Master

    3. * Test1


M represents the changes brought in from the original branch (the last modification was not committed).

5 Delete local branch git branch-d xxxxx

    1. $ git br-d test1

    2. Deleted Branch Test1 (was 17d28d9).


$ git BR

    1. Master


6 view local and remote branch-a. Front with * represents the branch where your current working directory is located

remotes/origin/head, Origin/master #啥意思呢?

"After clone is complete, Git will automatically name this remote Repository as origin (origin is just an alias, run Git remote–v or view. Git/config can see the meaning of origin) and download all of the data, To create a pointer to its master branch, we represent the remote branch in the form of (remote warehouse name)/(branch name), so origin/master points to an remote branch (from that branch we clone data to local) "

This is the result of executing git remote-v, see origin is actually a remote git address alias.

$ git remote-v

    1. Origin [email protected]:middleware/jingwei.git (FETCH)

    2. Origin [email protected]:middleware/jingwei.git (push)

7 Deleting a remote version

$git push origin:test1





This article is from the "Feng Songlin blog" blog, make sure to keep this source http://fengsonglin.blog.51cto.com/9860507/1726357

Mac is powered by git

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.