Friday, May 11, 2012

Git operation between remote and local repositories


  • Add the alias (stanford) to the remote repository
12:03 PM ~/Development/rails_projects/app_0515 $ git remote add stanford ssh://[username]@[ip_addr]/~/git/app_0515.git
12:04 PM ~/Development/rails_projects/app_0515 $ git remote
stanford
12:04 PM ~/Development/rails_projects/app_0515 $ git remote -v
stanford ssh://[username]@[ip_addr]/~/git/app_0515.git (fetch)
stanford ssh://[username]@[ip_addr]/~/git/app_0515.git (push)

  • Fetch remote repository into a local copy
02:28 PM ~/Development/rails_projects/app_0515 $ git fetch stanford
remote: Counting objects: 55, done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 51 (delta 2), reused 51 (delta 2)
Unpacking objects: 100% (51/51), done.
From ssh://[ip_addr]/~/git/app_0515
* [new branch] master -> stanford/master

  • Diff between the local, and remote repository which has been fetched to a local copy
03:22 PM ~/Development/rails_projects/app_0515 $ git diff master stanford/master --stat
Gemfile | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

  • Got an error pushing to remote repository. The error indicates git thinks the remote repository has recent pushes that are not synced into the local repository.
03:21 PM ~/Development/rails_projects/app_0515 $ git push stanford master
To ssh://[username]@[ip_addr]/~/git/app_0515.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://[username]@[ip_addr]/~/git/app_0515.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
  • Merge the pushes/changes in the remote repository into the local repository
03:22 PM ~/Development/rails_projects/app_0515 $ git merge stanford/master
Merge made by recursive.

  • Push to the remote again, this time it succeeds.
03:22 PM ~/Development/rails_projects/app_0515 $ git diff master stanford/master --stat
Gemfile | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
03:22 PM ~/Development/rails_projects/app_0515 $ git push stanford
Counting objects: 10, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 978 bytes, done.
Total 6 (delta 3), reused 0 (delta 0)
To ssh://[username]@[ip_addr]/~/git/app_0515.git
a0226b1..2523dd3 master -> master
03:22 PM ~/Development/rails_projects/app_0515 $ git diff master stanford/master --stat
03:22 PM ~/Development/rails_projects/app_0515 $




No comments:

Post a Comment