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
Related
What I'm trying to do is to version a file without ever pushing it to github, is it something I can do ?
Context :
For instance, I have a local database for dev (Django) which is SQLite3 which creates a file "db.sqlite3". I don't want this file to be on github, but I'd like to be able to reset it to previous version if I mess with the migrations for example.
Maybe they are better ways than git, I'm open to suggestions.
Thank you !
As far as I’m aware a file is either tracked (included in commits and pushes) or ignored. There isn’t a middle ground and I’m not sure there needs to be.
https://git-scm.com/book/en/v2/images/lifecycle.png
If you can isolate the file within its own directory- create a separate git repo for that directory and don’t have a remote associated with it.
Maintain git repo inside another git repo
Furthermore you could create an automatic schedule for git commits (using cron for example) so you can do point in time recovery for that directory.
If you can’t move the file then schedule a backup of the file to another folder and commit the backup to a different local repo.
Copy SQLite database to another path
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
I can setup a build trigger on GCR to build my Docker image every time my Git repository gets updated. However, I have a single repository with multiple folders, and a Docker file in each folder.
Ex:
my_app
-- service-1
Dockerfile-1
-- service-2
Dockerfile-2
How do I only build Dockerfile-1 when the service-1 folder gets updated?
This is a variation on this GitHub feature request -- in your case, differential behavior based on the changed files (folders) rather than the branch.
We are considering this feature as part of the development of support for more advanced workflow control and will post back on that GitHub issue when it becomes available.
The work-around available to you today is to use a bash script that conditionally builds (or doesn't) based on an inspection of the files changed in the $COMMIT_SHA that triggered the build. Note that the git builder can be used to get the list of files changed via git diff-tree --no-commit-id --name-only -r $COMMIT_SHA.
I have a git repo at repo1URL.git. It's a production repo and I didn't want to mess with it (in hindsight it would have been easier to just create a branch in that repo!).
It's a django app that is very poorly structured (with third party libs added as folders, rather than via virtualenv and pip.
I made a physical copy and deleted the .git folder of the copy, created a new repo at repo1URL-changes.git and added it as a new remote into the copy. Cleaned up things by removing unnecessary folder, etc, and pushed it to the new repo.
Now I'd like to merge those changes into the main production repo. I found the following question: how to import existing git repo into another
I followed the instruction # Selected Answer. But the results of the:
git merge ZZZ
is rather a nightmare! With conflicts even on .png files and almost every other file.
What's the best way to go about this?
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.