[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Proper git usage

Posted on 2011-05-06
6
Medium Priority
?
764 Views
Last Modified: 2013-11-13
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.
0
Comment
Question by:coanda
  • 3
  • 2
6 Comments
 
LVL 21

Expert Comment

by:developmentguru
ID: 35709799
Have you checked out the online documentation?

http://git-scm.com/documentation
0
 
LVL 3

Author Comment

by:coanda
ID: 35710746
Yes.
0
 
LVL 8

Expert Comment

by:eager
ID: 35712886
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".  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:coanda
ID: 35725050
@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.
0
 
LVL 8

Accepted Solution

by:
eager earned 2000 total points
ID: 35730359
I've been using git for a while and I'm impressed with its functionality, but it does seem to be confusing at times.

Do the following:
  $ ssh rev
  $ cd /srv/repos/git/project
  $ git checkout -b dummy

Now you should be able to push into the repository.

Here's a description of what is going on:
http://sitaramc.github.com/concepts/bare.html
0
 
LVL 3

Author Closing Comment

by:coanda
ID: 35731022
That fixed my problem, thanks a lot.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Screencast - Getting to Know the Pipeline

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question