Git basic workflow [duplicate]
Possible Duplicate:
git push error '[remote rejected] master -> master (branch is currently checked out)'
I am new to Git and trying to use it for a local grails project.
The steps I followed:- create the grails project
- go to the project directory and
git init
- Add all the files in the project in staging area and commit.
The git status at the repo gives the below message
BXX@BXX-PC /c/Work/Grails/projects/yyy/tables (master) $ git status # On branch master nothing to commit (working directory clean)
Trying to keep it as the master branch, make the changes by cloning the repo, and later push the changes back. For that
- In my IDE, checkout the project (IntelliJ).This actually clone the project to another dir.
- Make the changes and commit the project
Push the local changes to master.
15:41:56.249: git push -v origin master Pushing to c:/Work/Grails/projects/xxx/tables 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.
The cloned repo status is
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
Please help me with understanding this. Is there a better workflow to follow. I may be able t开发者_如何学Co initialize the repo through Intellij, and try to work on the main branch. Still not sure what is wrong above.
thank you.
The problem is that you're trying to push to a non-bare repo. A non-bare repo is one which has an associated working tree (that is, the files are actually checked out to disk). By default, Git won't let you push to a non-bare repo; pushing to a non-bare repo only updates Git's internal data structures, and does not alter the working tree (the files on disk), which means that if you then go back to the repo you pushed to and start working on the files, you'll be working on older copies of the files. Naturally this will cause problems when you try to commit your changes.
The best way to do this is to push to a bare repository, which is one created by passing the --bare
flag to Git when creating the repo:
$ mkdir new_repo
$ cd new_repo
$ git --bare init
Of course, the bare repo won't have any files checked out, so you can't actually work it in (you'll have to clone it first).
If you're just using a Git repo for local development (and not sharing or serving the Git repo), you don't have to have a remote repo to push to; you can work on a single copy of a local, non-bare repo.
First of all, you do not need to clone your local repository. You can use branches to divide development in the same repository.
Git is a Distributed VCS, and if you have experience with Subversion or CVS before it, you need to change your mind.
Git is a very agile and you can use different workflows with it. Cloning repositories is more needed for a team work, not for local development (IMHO).
Branches is a good alternative for you.
See. Let's set master branch of your repository for a production-ready code. Let's create another branch for development:
$ git checkout -b development master
Now you are working on the development branch.
You could use different branches for each feature you want to develop. It's very easy and helpful.
Let's imagine you want to implement some new feature, you need to create a new branch:
$ git checkout -b newfeature development
Now you can work with your code, add files, commit and so on.
Next you need to merge your new developed feature to the development branch:
$ git add .
$ git commit -m "My last changes for the new feature"
$ git checkout development
$ git merge newfeature
Now your new code from the newfeature branch merged into the development branch.
For sometime in the future when you decide that your code in the development branch get some milestone, you could merge all the changes from development to master branch.
It's a very basic workflow, it can be helpful for the many branches.
My advise for you now: read more about git, branching, stashing (very-very-very helpful for quick fixes). And after some time you will get a great effort from using git.
Good luck.
This is the clearest, most comprehensive description of a successful git workflow. It covers basically what Sergey suggests, with the addition of some very hepful graphics.
A successful Git branching model
The author also suggests when you merge to include the --no-ff
tag to keep record of the fact that you had a feature branch in history.
I ended up here when trying to fix the same kind of problem, fortunately there is a much better answer out there:
Git push error '[remote rejected] master -> master (branch is currently checked out)'
You should check that one out. Especially as it is pretty easy to end up in this circumstance. For me all I did was create a directory and git init it to make my new "shared repository". It was on a USB key because our network is completely locked down and we can't share a directory or access GitHub yet.
Then I copied all of our source into that directory, added it, committed it, and then cloned the resulting repository to my local drive so that one was now my origin. I figured I could later make GitHub remote and do away with the shared USB repository. However, my first change on the local drive and attempt to push to the remote (the key repository) gave me the message because the key repository wasn't "bare". All of the original files were out there still.
Consult the most highly rated answer on the linked to question to see what to do. The gist is that you set a flag in the shared repository so it thinks it is bare and then delete everything out of it except the .git subdirectory and your push will then work.
精彩评论