Why is git not pushing contents of a folder? - django

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.

Related

Git commit from a bisect

I have only ever used git add . for this project, but somewhere along the line I started getting the strange "modified content, untracked content" error on one of my subdirectories (called users). Other stackoverflow answers didn't work for me. I used checkout to go back through previous commits, but the buggy/untracked subdirectory didn't change with the rest of the directory. I ended up making manual changes to it and then running git checkout master to make sure everything else was back where it started.
Git is saying that I'm bisecting, and it won't let me commit. I looked over stackoverflow answers, and tried some of the following commands:
git pull:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
git pull origin master:
fatal: 'origin' does not appear to be a git repository
git branch --set-upstream-to=origin/master master:
error: the requested upstream branch 'origin/master' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.
git pull --rebase:
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
Apologies if these commands are all over the place. I intend to really learn how git works soon, but right now I just want to commit the changes so I can deploy my project.
UPDATE: I used git bisect reset, created a new branch out of my detached head, and then merged with the master. This kept the changes I made, so now I just need to figure out how to get users tracked again in my commits. git add users still isn't doing anything.

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

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

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.

Unable to push local changes live using Git Push Heroku Master

I'm new to GitHub and have gotten myself into a tangle. I've been successfully deploying code to a Heroku / Django app. However, my last commit was unsuccessful. This is my flow...
- Git add .
- Git commit -m "social media icons"
- Git push heroku master
The last command returns....
Fetching repository, done.
Everything up-to-date
Everything is not up to date. One thing I've discovered on my GitHub app is that I have 2 branches "production" and "master". Master was last updated Sept 8th. I've run a few commands including "git pull origin master" and "git push -f" based on other Stack answers. The latter did seem to push something but not the changes in local. Sorry, I'm trying to find my feet here!
If you're on production branch then you will need to do
git push heroku production:master
Heroku will only deploy the master branch so this command is you pushing your local production branch into the master branch on the remote.
So you are on branch production but your other branch master is up to date. If you want to push the current branch you are on, you should explicitly say so: git push heroku production.
I would highly advise you to try git, it's an excellent resource.

How do I push git commits in different Django directories to GitHub without having to keep doing pull merges?

I am pushing one set of commits to GitHub from my Django app directory and another set of commits from my templates directory. Because each is a different directory, I had to set up a git remote in each one so that it knows to push to GitHub.
Here's the problem: Each set of commits has its own "master" branch that isn't aware of the other. First, I push the commits from the Django app directory's master branch to GitHub's master branch and that works fine. But then, if I push the set of commits from the template directory's master branch to the same GitHub master branch, I get an error saying that I need to do a merge before I can push. The push goes through after I do the merge, but it's annoying to have to keep merging the GitHub master to the different master branches of my different Django directories.
My question is: is it possible to set one master branch for all the different django directories I need to work with so that i can just do one push for files in all my directories? It seems that I need to initialize a .git file for each directory I want to work with which consequently gives each directory its own master branch.
That is very strange. I use a single master branch for django projects that are hosted remotely on github.
You need to make a clone of the local repo in the topmost directory to have a single remote master branch.
For example, my project name is: BigCoolApp
If you do: cd /user/BigCoolApp
You should find a .git folder in there. It will be among all the other folders. If done correctly, you will now have a single master branch for your Django project.