Proper git usage

Posted on 2011-05-06
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

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.
Question by:coanda
    LVL 21

    Expert Comment

    Have you checked out the online documentation?
    LVL 3

    Author Comment

    LVL 8

    Expert Comment

    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".  
    LVL 3

    Author Comment

    @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.
    LVL 8

    Accepted Solution

    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:
    LVL 3

    Author Closing Comment

    That fixed my problem, thanks a lot.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now