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.
Related
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.
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!
As is shown in the image,I'm not sure if the failure is caused by some missing property while setting up webstorm .
The issue is not resolved after a lot of efforts.As a learner,I don't know what to do now.
Meanwhile,something seems wrong as shown in git bash.I've no idea whether the two are directly related.
If you have ever faced these difficulties,could you please give me some idea? Even if it's only a web address.
What I want to do is only pushing my code. Anyone who pushed successfully in any other way will be welcomed to share your method.
If I'm being honest I'm not sure that I completely understand your question, but I will supply some information that will hopefully lead you down the right track.
First in the bash shell, cd (change directory) into your project directory like this:
$ cd /c/foo/bar/yourprojectfolder
In your project top most directory, do you have a .git folder? You may have to show hidden folders in windows to see this directory. If not, you need to initialize a repository with the init command.
$ git init
Initialized empty Git repository in C:/foo/bar/yourprojectfolder/.git/
After running this command, you should see a .git folder inside of the directory you changed to (used cd to get to) earlier.
Next, in order to push, you first need a remote repository to push to. Based on your first picture, I believe that you have successfully created a repository on GitHub. If not however, just log into GitHub and click the 'New Repository' button:
Once a repo has been created, you need to add it as a remote to your local git (in git bash). To do this you need a url (either SSH or HTTPS) to your repo. You can find this url inside of your repository in online GitHub. If you are not certain you have set up SSH, it's best to use the HTTPS url. It should look something like this, but the url itself will be different and specific to your repository:
Copy that url to your clipboard, and then back in git bash run:
$ git remote add origin <PASTE YOUR URL HERE>
You need to make an initial commit of your code to have something to push:
$ git add .
$ git commit -m "Initial commit"
Finally, with the origin repo set up and a commit made, you should be able to push to your origin repo
$ git push -u origin master
You should now be able to view your code on GitHub.
Here is my problem
I am using heroku to develop an app and I am using github along with it for a project.
Now when I try and use github(clone) without heroku to work on a different project it says...
michael#michael-HP-PavilionNotebook-PC:~$
michael#michael-HP-PavilionNotebook-PC:~$
michael#michael-HP-PavilionNotebook-PC:~$ git init
Initialized empty Git repository in /home/michael/.git/
michael#michael-HP-PavilionNotebook-PC:~$ ls
Desktop Downloads gifiniti Music Pictures Templates Ubuntu One
Documents examples.desktop gifinitiApr24 oldgifiniti Public tmp Videos
michael#michael-HP-PavilionNotebook-PC:~$ git clone git#github.com:toadiferus/SecretTunnel
Cloning into SecretTunnel...
! Invalid path.
! Syntax is: git#heroku.com:<app>.git where <app> is your app's name.
fatal: The remote end hung up unexpectedly
michael#michael-HP-Pavilion-dv6700-Notebook-PC:~$
How would I resolve this error? Can't find any support online for this specific problem.
HOw can I change the syntax of the commands? I want to just clone a project from github not heroku.
THANKS!
Michael
Your ~/.ssh/config may have been hijacked by if you used the heroku accounts plugin. Same thing happened to me. I removed the contents of my ssh config and all is well!
Firstly, you don't need to init before you clone - init is used to turn a project folder into a git repository unless you really intended to turn your entire user directory into a git repo? I would suggest you delete the .git folder that would have been created from your doing this.
To be sure you're using the correct path go to your projects on github and use the icon that looks like a clipboard to copy the correct url to your clipboard, paste onto your command line and see what happens then.
I also don't understand why when you do a
git clone git#github.com:toadiferus/SecretTunnel
Cloning into SecretTunnel...
you get what looks like a Heroku push error??? Git clone from a github URL should simply clone the project from github to your local machine.
! Invalid path.
! Syntax is: git#heroku.com:<app>.git where <app> is your app's name.
Are you editing the output you are pasting?
The git url should have .git on the end, ie. git#github.com:toadiferus/SecretTunnel.git.
I have an issue with a new remote repository that when cloned using Tower, doesn't clone all the directories.
When I created the remote repository, I did the following:
Created a .gitignore file containing the following line
files/cache/*
Then ran:
git init
git add .
git commit
I then cloned the remote repository to my local machine using a Mac OSX git client called Tower but noticed that many of the directories did not clone.
When I go back and look at my terminal session on the webserver, I can see the directories that weren't cloned listed after the initial commit - I see a whole bunch of lines that look like this:
create mode 10644 directory-name/path/to/file.php
create mode 10644 directory-name/path/file.php
create mode 10644 directory-name/path/to/file.php
create mode 10644 directory-name/path/file.php
So I'm guessing they were added but I'm also wondering if my .gitignore file is not setup right and is conflicting with Tower somehow?
I tried the .gitignore file a couple of ways, firstly like this:
files/cache/*
then like this:
files/cache/
After changing it to the second one, I ran git add -A (which didn't seem to add anything new) on the server and pulled the repo down using Tower again - but no luck.
Not sure if this is Git or Tower or both - not sure what I'm doing wrong, sorry.
Any help would be much appreciated.
Cheers
Ben
Don't forget that git won't add (and clone) empty directories.
(or directories with ignored content, making them empty for Git)
See:
"Does git ignore empty folders?"
"How do I add an empty directory to a git repository?"