Thursday, January 19, 2017

Configure Git Remote Repository

As our company started using Git instead of SVN. and my Manager has asked me to help other developers who are left with Git Configuration on their development machines. so I though I should write a blog post and list steps involved.

Let suppose below are your credentials
GIT IP : XX.XXX.XXX.XX
Remote repository URL: /home/git/customers/xyz/xyzproject/android
Git User name: hammad.tariq
password: xyzpass

Now I assume you have GIT installed.

Step 1:
Go to your project source code folder right click and select Git Bash here
Git interface will be opened.

Step 2:
Now you have local repository(folder) and you need to clone it with remote repository.
(your local repository will be copy of remote repository, your code pulled from remote will be saved in local and code in local will be pushed to remote repository).

First Command 
git clone ssh://hammad.tariq@XX.XXX.XXX.XX/home/git/customers/xyz/xyzproject/android

-If you have entered valid information it will prompt you for password.
-If there is already code on that repository, another developer has pushed already. This command will pull that code and will save into your local repository.

This will be printed on console if everything fine.
Cloning into 'android'...

Step 3:
If there is no code in your local repository copy paste code into your local repository so you can push it into remote repository.

Second Command
git add -A

Third Command
git status

Fourth Command
git commit -a -m "First Commit version 1.0.1"


Fifth Command
git push origin master


Now it will start pushing code.

If you get errors like below:

1- Error
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit

Solution: Than you don't have write permission for specified repository.

2- Error
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://hammadtariq@bitbucket.org/hammadtariq/xyz.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.


Solution: You are doing "git push origin master", You need to run "git pull" first.


3- Error
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

Solution: 
git config receive.denyCurrentBranch ignore
run this command and try to push code again
Note: You need to run this command from server. (Git IP)



No comments:

Post a Comment

Kotlin Android MVP Dagger 2 Retrofit Tutorial

http://developine.com/building-android-mvp-app-in-kotlin-using-dagger-retrofit/