Link to home
Start Free TrialLog in
Avatar of coanda
coanda

asked on

Proper git usage

I'm trying to use git more because from what I've been able to figure out so far it's a pretty nice way to do revision control, but it is definitely difficult at times to figure out the work flow. I'm using gitweb on a local server to host my repositories so I have access to do anything on client and server, what I've figured out so far is
# create repository on the server
ssh rev
cd /srv/repos/git
mkdir project
cd project/
git init
touch .gitignore
git add .
git commit -a -m "initial commit"
git remote add origin ssh://rev/srv/repos/git/project
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git push --all
# add the project to gitweb
cd /srv/repos/git/public
sudo ln -s /srv/repos/git/project/.git project.git
exit

Open in new window


That all seems to work fine, although I wouldn't be surprised to learn that I was doing something incorrectly, or at least not using the best method. The next part is where I'm really confused, I would like to be able to clone the repository, create a branch and work with it, merge it back in, and push the changes to the remote branch. I'm trying to do this by
git clone ssh://rev/srv/repos/git/project
cd project
git branch development
git checkout development
touch new-file
git add new-file
git commit -a -m "added new file"
git checkout master
git merge development
git push origin master

Open in new window


and when I try to push at the end I get the error

Counting objects: 3, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 246 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
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'.
To ssh://rev/srv/repos/git/test
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://rev/srv/repos/git/test'

I have managed to get it to work by creating another remote branch "working" and using
git push origin working

Open in new window

but I get confused at that point and it doesn't seem like the correct way to do it.

I would really appreciate any help that would give me a good idea of how I should be working with git. Thanks in advance.
Avatar of developmentguru
developmentguru
Flag of United States of America image

Have you checked out the online documentation?

http://git-scm.com/documentation
Avatar of coanda
coanda

ASKER

Yes.
First, run "git status" to see what git believes the current state of the repository is.

If there are files which have not been committed, git will not let you push.

If there are changes in the origin which are not in your repo, you will need to sync first by doing "git pull --rebase".  
Avatar of coanda

ASKER

@eager, there are no changes made that are not listed above. The status shows that all changes have been committed and running pull --rebase shows that everything is up to date.
ASKER CERTIFIED SOLUTION
Avatar of Michael Eager
Michael Eager
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of coanda

ASKER

That fixed my problem, thanks a lot.