fatal: destination path '.' already exists and is not an empty directory - django

I'm getting this error when I try to git clone my Bitbucket repo from my remote Digital Ocean server. The server directory I'm trying to clone the repo into is not empty, as I'm setting up my Django project in it (env, static, manage.py etc are all in there). So how do I clone the repo into this directory that is not empty?
I've already tried a reccommended answer which said use git fetch and git checkout -t origin/master -f - and that didn't work - I got this error:
fatal: A branch named 'master' already exists
Any suggestions what I can do?

If I understand well, you have a folder in which you already have files that will be part of what you will clone.
What you can do is :
Initialize your folder as a GIT repository
git init
Stash all your files in your folder
git stash save -u
Add your remote repository URL
git remote add myremotepository git#github.com:X/Y.git
Pull the stuff :)
git pull myremoterepository master
Reapply the files you stashed
git stash pop (or git stash apply if you want them to still be in the stash memory)

Make sure the name of the project on your computer is different from the repo name. If they are the same, cloning will be impossible. E.g you could name your repo as project_java and the actual name of the project on your computer could be project

Related

Build error "file not found" after git pull --rebase origin master

Remote repo has made some changes to project settings (added new folder and changed include path). How do I pull these settings into my repo please? I tried
git pull --rebase origin master
And then build the c++ codebase but the build throws "File not found". Appreciate any help this beginner can get.
It is indeed git pull origin master but:
check first git is recognized in your current shell and $PATH
git version
check you are in your local repository
cd /path/to/local/repo
git remote -v
git pull --rebase origin master

Add an existing origin to a django project and pull the existing repo in it.

I am new to GIT hub version Controlling System.
I am working on a project which i downloaded as zip from GIT hub. It is not a git repository. What i want to do is that I want to make it a git repository and want to pull the existing git repository in it when issuing a git pull command.
I want to create my own Development Branch, develop code on local, push code to github, then do a pull request
Help will be highly appreciated.
Since you don't have any history of your changes to preserve I think your best bet is to clone the repo normally, and then copy your changes into that repository. Your question is a bit sparse on details, but something like the following should work
git clone <git hub project> <new folder on your system>
# maybe you can use a tag here for the SHA
git checkout -b my_branch SHA_THAT_REPRESENTS_YOUR_ZIP_DOWNLOAD
cp -r <your existing directory> <your new git repository>
git status # abort if this step doesn't look right
git add # add all your changed files
git commit # commit your work
git rebase <main dev branch> # catch up

Using Bitbucket for existing project

I have an existing django project on my local machine (in virtualwrapper). How do I add it to the Bitbucket?
Let say my django project is like this:
project
--manage.py
--apps
--db.sqlite3
...
So should I do 'git init' under 'project' directory?
Since it is develop in the virtualwrapper, so I think only the project files will be pushed to the Bitbucket, is that right? If I want to develop the project on a different computer, and want to pull the project files from Bitbucket, how should I do it? I mean should I create another virtual environment in my new machine, install django and necessary pakcages before import the files from bitbucket?
I am new to git, so I don't know what is the best to do it.
So should I do 'git init' under 'project' directory?
Yes, but after that, don't add everything.
Create a .gitignore file first, where you declare the files that shouldn't be versioned (the one that are generated)
Then add and commit: that updates a local repo.
you can easily link it to an existing empty BitBucket repo:
git remote add origin ssh://git#bitbucket.org/username/myproject.git
git push -u origin master # to push changes for the first time
Normally, you wouldn't store a binary like db.sqlite3 in a source repo.
But this blog post suggests a way to do so through
In a .gitattributes or .git/info/attributes file, give Git a filename pattern and the name of a diff driver, which we'll define next. In my case, I added:
db.sqlite3 diff=sqlite3
Then in .git/config or $HOME/.gitconfig, define the diff driver. Mine looks like:
[diff "sqlite3"]
textconv = dumpsqlite3
I chose to define an external dumpsqlite3 script, since this can be useful elsewhere.
It just dumps SQL to stdout for the filename given by its first argument:
#!/bin/sh
sqlite3 $1 .dump

post_receive hook in git: how does it checkouts my non-git folder?

I am using webfaction for my web deployment.
I have a Django app at: webapps/django_app/project_name/
I have a Git repo at: webapps/git_app/repos/my_repo.git
my_repo.git is a bare repository. It is not a working directory.
whenever I push from my local development computer to the remote (webfaction --> my_repo.git), I want my django_app to get the pushed code.
I followed this post which works fine. But no explanation of how this works is given.
I have added these two lines in post_recieve hook in my_repo.git.
#!/bin/sh
GIT_WORK_TREE=/home/username/webapps/django/myproject git checkout -f
GIT_WORK_TREE=/home/username/webapps/django/myproject git reset --hard
what does this two lines actually do?
Moreover, my Djangoapp folder is not a git repo. still whenever push is made to my_repo.git, Djangoapp gets updated. so how does it work?
When you are managing files locally with .git, you typically have two things:
Your git repository, which is contained in the .git directory, and
Your work tree, which is the set of files you are actually editing.
By default, the repository is a subdirectory of the work tree, but this is not a requirement. Setting the GIT_WORK_TREE environment variable directs git to use a different location for your checkout out files.
So the first line...
GIT_WORK_TREE=/home/username/webapps/django/myproject git checkout -f
...is asking git to check out the HEAD of the repository into /home/username/webapps/django/myproject.
The second line...
GIT_WORK_TREE=/home/username/webapps/django/myproject git reset --hard
...makes sure that /home/username/webapps/django/myproject does not have any local changes. reset --hard discards any changes to files that are tracked by git. By "local changes" I mean any changes that you or someone else has made to files in this directory; ideally, there won't be any, but if there were some there, reset -f makes sure that the modified files are overwritten with the version of the file stored in the repository.
For more details on any of the commands listed here, try running git <command> --help for the man page, or see The Git Book.

Why is git not pushing contents of a folder?

After copying a folder 'myapp' into to my working folder, I do the following to add it to my staging area:
git add .
and then commit the changes:
git commit
Then I push my changes to Heroku:
git push heroku master
So my folder, called 'myapp' is present on heroku, but the problem is that it's completely empty.
When I do the following,
git clone myapp myapp2
the folder clones properly on my local machine with all expected subcontents.
Does anyone know why the subfolders' contents are not being pushed to Heroku properly? What am I doing wrong?
To answer the questions below:
I am doing the git add . in my top level folder (the folder that contains folder myapp). Doing git status shows `no changes added to commit (use "git add" and/or "git commit -a")
Yes, myapp contains files/folders (my django project)
I deleted my .gitignore file because I placed my virtual environment in another place altogeher so it's no longer in my project folder so I don't think that's affecting it.
Ok, I seemed to have solved the problem. Somehow git got in a weird state. I don't really understand how, but for some reason it wasn't adding any of the files in the folder.
I simply copied that folder and gave it a new name, and then followed the exact same process I had been doing all along, and it finally uploaded properly.
By default, you cannot push changes to a checked-out branch of a repository. It usually causes major problems! Here is what usually happens:
$ git push heroku master
...error messages...
To heroku
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'heroku'
Since you haven't mentioned any error messages, I'm assuming that you've added the following to your heroku repository configuration, or you're running a fairly old version of Git:
[receive]
denyCurrentBranch = false
It sounds like you want to check out a fresh copy of the master branch whenever you push a new version to your heroku repository. That can be achieved with a post-receive hook. Create a file in your heroku repository .git/hooks/post-receive, and give it +x permissions.
#!/bin/sh
while read oldrev newrev refname
do
if test "$refname" = refs/heads/master
then
( cd ..; GIT_DIR=.git; git reset --hard )
fi
done
Now, whenever you push a new master branch to heroku, the hook will run and check out the new branch. There are better ways to do this kind of thing, but this is simple.
Summary: By default, when you push changes, it only changes the history but not the working tree. The assumption is that someone might be working on that tree, so doing anything to it could be destructive.