I have a laravel app on Cloudway DigitalOcean, my app in /public_html , I want to update my app using git , so I have created folder private_html/git , where I pull my edited project from bitbucket, now I want to checkout it to my public_html/ , how do I do that ? Thank You
You can either deploy the changes to public/html via git or manually copy the files across.
Manually copy option
Depending on full path, something like:
cp -a private_html/git/. public_html/
Note: -a is a recursive option that preserves file attributes
This won't remove any files that have been removed in private_html/git so you would have to do that manually, or remove everything before copying the files across.
Git pull option
First, make sure you have pushed all the changes made in private_html/git to your remote (bitbucket repo).
Set up the current copy in public_html/ as a git repo.
In public_html/
git init
Then add the bit bucket remote
git remote add origin git#bitbucket.org:user-name/repo-name
Note: Get the proper bitbucket remote from your bitbucket account
Then pull the changes from the remote
git fetch --all
git reset --hard origin/master
Warning: You'll lose any differences that are currently in public/html so be careful. Always a good idea to back up everything before these kinds of changes so I'd suggesting archiving the code in public_html before overwriting it.
Related
I want to clone the last committed files via Git. I tried the --depth 1 parameter. But the all project was cloned. I want to download only the last edited files because the project size is too high.
The command I tried;
git clone --depth 1 https://USERNAME:PASSWORD#HOST/PATH
I want to clone last edited and updated files. I don't want to go back to the previous committed files. I will analyze the last edited files with SonarQube. I don't want to clone the all project for this. And : I'm using exec with PHP to run commands.
How can I clone only the last edited files? Thank you.
You can't just download a couple of files from a remote git repository. In order for git to restore a file, it must have all the data of the repository available. So unfortunately you will have to download the whole repository. If you would like to see which files have been changed, you can then run git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD to receive a list of modified files.
$ git archive --format=tar --remote=<repository URL> HEAD | tar xf -
Also, if your browse remote repository using some web interface like Gitweb or GitHub, then it may have 'snapshot' feature with it and you can also download the newest version.
My GIT repository is located /var/repo/myRepo.git. I set a GIT hook post-receive* to copy the files from my repository to the folder of my project
git --work-tree=/var/www/laravel --git-dir=/var/repo/myRepo.git checkout -f
Each time I commit and push something on the server, the file var/www/laravel/config/services.php is replaced and the modification I did on the server is replaced by my local copy.
For instance, if I manually modify the following file like this on the server (by ssh session)
var/www/laravel/config/services.php
This is the modified content of this file
It will be like that after a commit and push
var/www/laravel/config/services.php
This is the default content of this file
I tried to add /config/services.php to my .gitignore but it does not seem to work.
.gitignore
/node_modules
/public/storage
/public/hot
/storage/*.key
/vendor
/.idea
Homestead.json
Homestead.yaml
.env
/config/services.php
What should I do so this file is not replaced each time I commit something on my server ?
What should I do so this file is not replaced each time I commit something on my server?
You have only two options:
don't check it in, or
don't check it out.
Your git checkout -f command means "get me the latest commit, overwriting everything." If the latest commit has a new version of a file, that overwrites the old version of the file.
(Moreover, a .gitignore file does not mean what you think it means. It's not a list of files to ignore. It's a list of files—or name patterns—not to complain about. Usually most important, it lets you declare to Git: "Yes, I know these are in my work-tree and not in my index; don't tell me that." That's on the input side—i.e., the "don't check it in" part.)
This leads to a general rule about configurable software, where the software itself is maintained in Git, or indeed any version control system: Do not put the configuration into the version control system. The configuration is not part of the software.
Consider Git itself, for instance. You must configure Git to tell it your user.name and user.email in order to make commits with your user-name and email address. Now imagine Git came with its configuration file built into the software, that said your user name is Fred and your email is fred#fred.fred. Every time you updated Git to a new version, it would change your name back to "Fred <fred#fred.fred>". That's not very friendly, is it?
Git stores your configuration outside of the Git software. There are, to be sure, default configuration entries, but anything you set, is kept elsewhere. Updating Git does not touch this. This is not specific to Git, or even version-control systems: any system that provides upgrades must not store its configuration in a file that is destroyed by the upgrade.
So, stop doing that.
I did git rm /config/services.php and reimported the file manually. Now the file is not replaced by GIT.
I am having a really strange problem. I'll try keep it simple.
I am developing a web app using Laravel and it involves allowing users to upload and download files. I have created a function that allows a user to upload a file. This works grand. I can login to my site from another computer and see that the file was uploaded, and I can download it. So it seems to be working grand.
However, the file that I have uploaded is not appearing in the folder which it is supposed to on GitHub. This is really strange because the file definitely is there...because I can download it from another computer.
Code for uploading the file.
$destinationPath = public_path().'/files/';
$file->move($destinationPath, $file->getClientOriginalName());
I cannot see why the file I have uploaded isn't appearing on Git seeing as it has definitely uploaded.
Any ideas?
The files that you are looking for are located on your server. Adding or removing files from the server does not add or remove them from your git repository. In order to add them to your git repository, you would need to run the git commands to do so. The commands depend on what exactly you want to add, but as a general example:
To add all files
git add -A
Followed with a commit
git commit -m "example commit"
They will not appear on GitHub until you push
git push origin branch-name
For Git you have to manually commit the files.
Go to your command line and run
git status
If it shows public/ files then you would need to manually add them.
git add public
If they're not showing there, they're either being ignored or they've been committed and possibly not pushed.
First thing inside your project folder if the .git folder is created, delete it. Then write this series of code
commands:
git config --global user.name "your name"
git config --global user.email "your email"
git init
git add .
git commit -m "Initial commit"
git status
git remote add origin # paste here ssh link from github repository
git push origin master
Have a look at your .gitignore file. It might be the case that you instruct Git there to ignore the file.
How to upload my project to server , migrate my database , and edit my project using github or any other way .
i tried this way and it seems to be very stupid.
i uploaded myproject.zip and extracted .
then created database and imported a backup from my localhost database.
suggest any helpful easier way to do it .
thanks.
Maybe git-ftp is something for you.
You can use git-ftp for script based projects like PHP.
Most of the low-cost web hosting companies do not provide SSH or git support, but only FTP.
Git-ftp provides an easy way to deploy git tracked projects. Instead of transferring the whole project, it only transfers the files that changed since the last time.
Even if you are playing with different branches, git-ftp knows which files are different. No ordinary FTP client can do that.
First of all create a repository on github. And then on your local computer initialize git if you are on Linux (ubuntu to be precise) navigate to your project folder and run
git init
it will show an output about initialized a working directory or something like that. Navigate to .git folder and edit config file with your favorite editor, the content looks like the following
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://your-username#github.com/your-user-name/your-repository.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
after modifying this file navigate back to your project root folder and run
git add .
git commit -m 'first commit'
git push origin master
now login to your server via putty or any ssh client you use navigate to your project root folder initialize git by
git init
navigate to .git folder and edit the config file paste the same code you pasted on your local machine and then navigate back to your project root folder(on server) run
git pull origin master
You are in sync now. No anytime you make any changes to your localhost you should perform following commands from your project root folder
git add .
git commit -m 'any custom message about these changes'
git push origin master
and from your server
git pull origin master
Never make any changes on your development server in ANY CASE. you should add the files you want to ignore while upload and download in the .gitignore file under your project root in your localhost. e.g to exclude a folder from uploaded add following in your .gitignore file
/foldername/*
So here's what happened:
I have a local repo for dev
pushed to origin master
from my test env I always do git pull to update
Now of course I have different config files in the test env.
I locally changed my config file on test env.
In a hurried moment (...) I committed my local changes after a merge was conflicting.
Now the app runs fine, but git tells me
Your branch is ahead of 'origin/master' by 13 commits.
I understand, as I committed my local change - which I do NOT wish to push to master.
What would be the correct way to fix this? I want to:
Have my local copy of the config file
do not want to mess up with the basically correct config on the test env
get rid of the 'your branch is ahead' message
keep my master and my test env clean
Thanks!
You want to throw away your local commits on dev with
git push -f . origin/master:master
or
git reset --hard origin/master
if you are on that branch already.
The best way to treat config transformations is with smudge/clean scripts. They are explained it the progit.org/book in the attributes chapter. You commit a config that will work nowhere. Rely on the scripts to transform the config to what it needs to be on each environment.
If you just want to change your most recent commit, it is pretty easy. You stage the changes you want to make, and then amend your last commit.
In your case, you would change your config file back to the way you want it, stage it, then commit an amendment. Using config.php for your config file, it would look like:
$ git add config.php
$ git commit --amend
See the Rewriting History chapter of Pro Git