How to load laravel project from github instead form localhost - laravel

I'm working on laravel project and try to use github to share code with my colleagues. I can setup project use git clone command. But once my colleague update project and push server then my code already out of date. So how can get that new update to overwrite my existing using git command.Any advice or guidance on this would be greatly appreciated, Thanks

Rather than overwrite, the best practice is to replay ("rebase") your local commits (that you do not have pushed yet) on top of the remote (updated) branch.
With Git 2.6+, type:
git config --global pull.rebase true
git config --global rebase.autoStash true
From there, a simple git pull will be enough.
You can then test your local code on top of what your colleagues have already pushed.

Related

How to push a new code to an existing git repository in github

I need to push my modified new java code to my old git repository in github but I do not have old code in my pc. How to do that?
I had push a code before my github account before. Now I don't have that old code in my pc. How do I pull the project into my pc and after making changes, push again to the same repository?
I do not have much experience in github, so please help me to improve skills on github.
Check your remote first to see where it is pointing to by
$ git remote -v
origin ssh://git#<old-git-url>/<project>.git (fetch)
origin ssh://git#g<old-git-url>/<project>.git (push)
Change the pointing to GitHub
$ git remote set-url origin ssh://git#<github-url>/<project>.git
Now your repo is pointing to Github
Now you can make your changes and then add them and do a commit and finally push to remote branch; say you are on master.
git add <file>
git commit -m <commit message>
git push origin master
I had to do just that and achieved it like this.
Setup. I assume you have a new remote repository with files that may not cause a conflict with the directory you currently have locally.
Git clone from the git repository you need to push to. Just make sure you create a new directory for the cloned code.
Copy the contents of the cloned repository into the local directory that has your current code. Make sure to copy the .git (hidden) file.
cd into your local directory and run git remote -v. You should see the remote repository git address.
git add -A to add whatever change you require and commit it.
Finally git push
You need to make sure that your local repository (the one that is on your computer) is connected to the remote repository (the one that is on the GitHub servers).
After this, you need to add the modified file to the staging area. Say, you have a file test.txt that you have modified, you would add it to the staging area by typing
git add test.txt
After that you would need to commit those changes. You can do that by
git commit -m "commit message"
And that's it, you have now saved those changes and recorded them in the version control. But the changes that you made have only been recorded in your local repository and you would need to push these changes to the remote repository (the GitHub servers). You can do this by
git push origin master
It would take a few seconds (depending on your internet speed and the project file size) to push these changes to the remote servers. Once it's done, you can open that repository on GitHub and see the changes for yourself.
Just to amend this a bit. I believe "master" is now "main" in some instances or platforms. If this answer isn't working for you, try swapping that out. It worked for me.

Change git repo from remote host

I have laravel-vue.js framework web site project that another developer coded on digitalocean.
Also there is a git file in the framework.
I want to use git, too. However, there is another git ssh link in project.
git#gitlab.com:user/projectname.git
I created a gitlab repo but i couldn't decide what to do next.
git#gitlab.com:myuser/projectname2.git
How can i get this project to my local and do changes on git.
Generally i use phpstorm for coding.
Thanks.
You need to change your git origin url in your repository.
Use git remote set-url origin new.git.url/here to replace old git URL with the new one.

Trouble setting up a laravel instance across servers using git

I am struggling with properly configuring a git workflow for a laravel project. I created the laravel project locally. At the base directory I used the git init command. Then connected the repository to the bitbucket repository set up by the company I am working for like so:
git remote add origin https://address/xyz.git
I then made some new changes to a few of the files. Did a commit and then pushed to origin like this:
git push -u origin master
Now I logged into our development box (which is not my local dev box). Built the laravel default laravel application and then tried to pull down the project specific files by connected the dev box's laravel directory to the same repository, but I keep getting the following error:
error: The following untracked working tree files would be overwritten by checkout:
.gitignore
composer.json
package.json
resources/js/app.js
resources/js/bootstrap.js
webpack.mix.js
Please move or remove them before you can switch branches.
I know I probably missed some simple step or did not set up the development box correctly, but I can't find this scenario in the documentation and I can't seem to discover what I did wrong. Can anyone help?
It sounds like the repository on the main development box has some local changes that are not checked into git. Run the command
git status
On the remote development box. This will tell you any local changes.
If you want to remove any local unchecked in changes you can type
git reset --hard (resets any tracked files)
git clean -Xdf (resets all untracked files)
If you want to preserve any local changes, you can type
git stash
git stash --pop (recovers the changes - this may induce some conflicts)
Thanks for listing those tools Ben W, but it turns out that I the wording of my question was deceptive. When I went to the second machine (the development box), I should have built the laravel instance by using the git clone command.
git clone https://address/xyz.git
What I did instead, was build another full instance of laravel and try to link it to the same repository I created from the first box (my local notebook).
I upvoted your answer anyhow Brad W. because those are all great tools to know. Thanks.

Issues getting Git working with VSCode and files on web host

Until now I have always used FileZilla for transferring my local files to my host for changing a site Im working on. I want to change that and learn how to git gud! So basically the ideal situation would be to be able to work in VSCode on a directory which is mirrored from my web host and from there be able to make changes locally and then commit and change files on my web host when I want to - this has to be possible right?
I have been able to use Git Bash to connect to my host and files using ssh. I have created both an init --bare and init since Im not sure which one to use, but I do have the .git folder created there. I can also using the Bash and the command git status see all the files waiting for to be committed (?).
As I understand I have to initialize the repository, then commit them to "track" these files and have them visible in VSCode to work with, is this right?
But when I try to git commit following error message is displayed.
Waiting for your editor to close the file... code --wait: code: command not found.
This points to that the relative pathing to vscode and/or git is not working, but it is. When I start-up the bash I can use for example code --help and git config --global -e to launch a window of VSCode. So my git config --global core.editor "code --wait" is probably working as it should.
Although AFTER I have connected to my web host using ssh, neither of these command work anymore. Why is this?
And also, am Im on the right way right now in thinking on how to make this "connection" between VSCode, git and my web host (one.com)?
Im thinking that I have to create a local repository in the folder where I today have a duplicate of my web host-files and a remote repository at the actual web host and then make some kind of connection between them two and VSCode. Im not quite sure how yet.
Thanks in advance
I think you might be a little confused with what Git is and how you should be using it for what you want to do. Let's clear some stuff up.
Simply put, Git is a version control system for tracking changes to files over time. You create or edit your files, git add them to a "staging area" and then git commit them with a commit message. If you edit the files after committing them, then git can detect changes to the files and you can add and commit them again, or discard them depending on what you want. However the most important part to understand is that these changes are local at this point. If you want to share them with anyone (or have another system pull them down), then you will need to establish a remote repository.
This is what Github/GitLab are for. Log in/create an account on either site (gitLab provides free private repos) and create a repository named appropriately. Then once you have created a remote repo, follow the instructions to add it as a "remote" to your local repo, then git push your changes up to that remote one. Now, on your server, you will git clone the remote repo and that will pull down your changes. From then on, if you push new changes to the remote repo, you can pull the changes down to the server by doing git pull. This is a very basic and barebones approach to deploying code on the server and there are more sophisticated ways of doing it but I will keep it simple in this answer.
Git is completely separate from VSCode (although VSCode has some git integration and plugins). I would not recommend changing the core.editor to VSCode. What that setting controls is the editor that is used to author commit messages. Loading up VSCode takes too long for that...I recommend that you stick with the default Vim or use nano. Or, in most cases, specify a message when committing: git commit -m "added foobar".
So, the git repo that is on your server (the one that you init'd with --bare) is junk and should be instead created by git cloneing from a remote repo. Hopefully this makes sense!

Git on live Windows Server - Trying to pull from the repo but local files already modified

I have my Git repository hosted at github.com. I would like to push updates and such to github.com and then log into my Windows server and do a git pull to get my changes (that are verified to work on my local machine. Ideally I should have another server setup as my local machine settings are different from the live server. But I'm cheap.).
It seems like whenever I try to do a git pull on the server, the files seem to get modified somehow since the last pull. And so I am unable to get the update as git says I need to commit my local (Windows server) changes.
How can I use git like I want to? Or is there a better way?
Is it possible you change the git core.autocrlf flag after cloning the repository?
Issue 83 on the google code project form msysGit goes deeper in on this topic.
If that it the case, doing a new clone should fix the problem (as long as the flag is not touched).
Are you using the Git GUI or Git Bash?
For some reason, Git GUI on Windows does not have core.autocrlf configured by default when cloning a repo, even after attempting to set core.autocrlf in the global configuration using Git Bash (might be GUI setting or environment issue that if corrected, could make the GUI a viable option).
Also, for some reason Git GUI in some cases seems to think it's better to make a master branch in the new repo rather than using the existing branches in the repo being cloned. After Git GUI makes this master branch, it then does a checkout of this master branch immediately after the clone. Since you're using a pull and having issues, this might only have been the issue if you initially cloned using Git GUI.
Most likely, it you're core.autocrlf setting. The following steps should set up a repo for you and ensure the proper crlf settings...
Steps to Clone without Modified File Garbage:
Using the following command in Git Bash from the Windows folder clones the repo as a full copy without making an initial checkout of a branch.
git clone –n --no-hardlinks
By not checking out the branch when cloning, you now have the ability to verify your .git/config file has the correct settings for autocrlf before checking out the branch. You might want to add safecrlf just to be safe ;) To update these settings crlf settings, execute the following commands from your newly cloned Windows repo using Git Bash:
git config core.autocrlf true
git config core.safecrlf warn
To verify the changes made it correctly, open your .git/config file and you should see:
autocrlf = true
safecrlf = warn
PLEASE NOTE: You want autocrlf set to input in your Linux repo... setting to true is for your Windows repo. Also, I only use warn on safecrlf, you may want to use true.
Once you have your crlf configuration set, you can finally checkout the branch normally using git checkout .
If there are still modified files in your new local Windows clone, it's likely due to having CRLF instead of LF in your Linux repo. This can be verified by using a hex editor on the files in your Linux repo and searching to see if 0D0A is present, or if everything is just 0A as it should be.

Resources