Uploaded files not appearing in Github - php

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.

Related

Clone latest committed files on Git Repo

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.

GIT Ignore and GIT Hook - File is replaced after a commit-push

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.

Git checkout from one directory to another on server (cloudways)

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.

Laravel - How to maintain my project on server using github

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/*

What is the best solution when deleted the local working copy in git

I was working in local git folder and committing with bitbucket. Accidently the local copy was deleted. But I had the latest local copy without .git folder. So cannot commit now. The solution I know is deleting the local copy and clone again from bitbucket. But I want a better solution for this. What is the best solution using git commands for this problem. Thanks.
I have tried to migrate code to git from clearcase.And I think my solution will match your issue.
Just keep your local copy and clone a new one which you want to push to.
And then solution is here: copy the .git folder to your local copy folder. Try git status you'll find it works and then just commit what you want.
Good luck!
Perhaps this will meet your issue.
firstly enter your local copy dir,and execute below:
> git init
> git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url <YourUrl>
> git config branch.<branchname>.remote origin
> git config branch.<branchname>.merge refs/heads/<branchname>
> git pull
> git add .;git commit -am "****" #Here commit your change, may you'll meet conflict issue.
> git push

Categories