Git project cooperation (Remote pull push) Learning

Source: Internet
Author: User

First, let's take a look at a small problem with removing the project from the server:

[Root @ localhost repository] # git clone root@74.207.254.10:/usr/local/system/Repository/blog
Initialized empty git repository in/root/Repository/blog/. Git/
Bash: Git-upload-Pack: Command not found # the error is reported. What is the problem?
Fatal: the remote end hung up unexpectedly

Google knows that the path of the git-upload-pack command is/usr/local/git/bin/, which is not in the non-Login Shell path (/usr/bin ), the solution is as follows:

# Fix it with symlinks in /usr/bin
[root@li96-10 ~]# cd /usr/bin/
[root@li96-10 bin]# ln -s /usr/local/git/bin/git* .

First, initialize a git project on the server:

[Root @ li96-10 repository] # mkdir blog. Git
[Root @ li96-10 repository] # cd blog. Git/
[Root @ li96-10 blog. Git] # git init -- bare # Must be added -- bare, and the directory cannot have any files and directories, otherwise the error: Fatal: out of memory? MMAP failed: no such device
Initialized empty git repository in/usr/local/system/Repository/blog. Git/

Next we will create a git project:

[root@li96-10 blog.git]# cd ..
[root@li96-10 repository]# mkdir test.git
[root@li96-10 repository]# cd test.git/
[root@li96-10 test.git]# echo "some content" >> file
[root@li96-10 test.git]# git add file
fatal: Not a git repository (or any of the parent directories): .git
[root@li96-10 test.git]# git init
Initialized empty Git repository in /usr/local/system/repository/test.git/.git/
[root@li96-10 test.git]# git add file
[root@li96-10 test.git]# git commit -am "first commit"
[master (root-commit) 3ea3176] first commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 file

Push test. Git to the blog. Git project.

[root@li96-10 test.git]# git remote add origin ../blog.git
[root@li96-10 test.git]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ../blog.git
* [new branch] master -> master

Now we can clone it from blog. Git:

[Root @ li96-10 blog. Git] # CD ..
[Root @ li96-10 repository] # git clone blog. Git # because our reposi is blog. Git, it will be blog after cloning
Initialized empty git repository in/usr/local/system/Repository/blog/. Git/
[Root @ li96-10 repository] # cd blog
[Root @ li96-10 blog] # ll
Total 4
-RW-r -- 1 Root 13 Jan 4 File

We can see that there is a file in the project, which we just pushed in.
Next we will add a file in the New Clone branch blog to see,

[root@li96-10 blog]# echo 'Second file contents' > file2
[root@li96-10 blog]# git add file2
[root@li96-10 blog]# git commit -am'added second file'
[master 63be855] added second file
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 file2
[root@li96-10 blog]# git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

Then we push it to blog. Git.

[root@li96-10 blog]# git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 280 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /usr/local/system/repository/blog.git
3ea3176..63be855 master -> master

In this case, our blog. Git already has two files: file and file2.
Next we will go to test. Git and merge the modifications we just made in first:

[root@li96-10 blog]# cd ../test.git/
[root@li96-10 test.git]# git fetch origin
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ../blog
3ea3176..63be855 master -> origin/master
[root@li96-10 test.git]# git merge origin/master
Updating 3ea3176..63be855
Fast forward
file2 | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 file2

We can see that the first modification has been merged. In the above operation, we use fetch and merge. In fact, we can simplify the two commands into a pull command:

[root@li96-10 test.git]# git pull origin master
From ../blog
* branch master -> FETCH_HEAD
Already up-to-date.

To sum up, the command used to get the version library is pull, and the command used to merge the local modification with the version library is push. Pull is required before pushing!
Of course, these operations are performed on a single machine. The following shows how to connect to a real remote machine using the SSH protocol:
Clone from remote:

[Root @ master repository] # git clone SSH: /// gituser@xxx.xxx.xxx.xxx/path/to/Repository/blog. Git
Initialized empty git repository in/root/Repository/blog/. Git/
Remote: counting objects: 1055, done.
Remote: compressing objects: 100% (822/822), done.
Remote: Total 1055 (delta 115), reused 1055 (delta 115)
Grouping objects: 100% (1055/1055), 1.29 MIB | 19 kib/s, done.
Resolving deltas: 100% (115/115), done.
[Root @ master repository] # ll
Total 4
Drwxr-XR-x 17 Root 4096 01-05 20:57 blog

Then, when we make changes locally and want to submit the changes to remote, we can directly push them:

[root@master repository]# cd blog/
[root@master blog]# git push
Everything up-to-date

This is basically OK!

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.