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

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.

Related

Cannot git checkout master: invalid path '?'

After an "unsuccessful" git pull on my local master, an error prevents to switch back to master:
C: repo_folder> git checkout master
error: invalid path '?'
The ? must be because it is a keybase repo.
From another branch where I checked out some files of the last commit:
C: repo_folder> git diff origin/master --compact-summary
"\004" (gone) | 1902 ---------------------------
some irrelevant stuff | (num) -
The removed file "\004" (that was never present in my local) seems to come from some Mac OS (someone might have opened a csv and a temporary file was created when that user did the commit and pushed?).
observe that the file that is marked as (gone) is to be removed by git
the problem is that the filename has characters that are not compatible with the Windows file system and that the file never existed in my local Windows repo.
If I clone from a Linux platform, I can checkout to master with no problems. However, in Windows, there's no way back to the master branch.
Any ideas on how to solve this issue? (already tried some posts with no success)
I can't really understand how it comes git doesn't even allow me to checkout to master. Should I file a bug report?
Alternatively, perhaps I could create a new master branch and get rid of the current one.
EDIT
A clone from Linux helped to identify that the file ? was actually there.
This could be checked directly from Windows as well by using the command: git ls-tree origin/master (which was showing the original problematic name "\004")
The accepted answer includes the case where you want to save the content of the file, while in my case I only wanted to get rid of it. So in my case, I have just deleted the file from Linux, committed and pushed the change, and did a git fetch origin master:master to fetch my local master with being checked out in another branch (as I was not able to checkout to master). This finally did the trick and I could checkout to master.
Hope this clarifies to someone with a similar problem.
? (or maybe it's EOT) cannot be used as a filename on Windows. The file will have to be deleted or renamed. You can do this most easily by cloning on a system which does allow ? and making the fix.
If you only have Windows, Fixing Invalid Git Paths on Windows offers a method of renaming the file without checking it out. In brief...
git checkout origin/master -f to get the checkout without the problematic file.
Make a branch.
Add and commit the "deleted" problematic file.
Use git ls-tree HEAD^ to get the ID of the problem file.
Use git cat-file -p <ID> to get the content of the problem file.
Put the content into a new file.
Add and commit.

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.

git on Mac sees files I havent touched as modified and they also appear as staged already

I am seeing strange behavior on Mac with git. I dont see this happening on Windows. Using git v 2.19.1 on mac and 2.18.0.windows.1 on windows.
I work in a crossplatform team, so some of us use Windows, others use Mac. I use both.
Here is the scenario I see:
I work on my feature branch for few days and like to make sure I update my branch with latest changes on remote so I always work on most recent version of remote. So, I daily do following to reduce chance of conflicts and stay on most recent version:
git checkout develop
git fetch origin
git merge origin/develop
git checkout my-feature
git merge develop
Once that is done, I apply my changes to my-feature branch but I notice that git behaves very strangely on Mac. Here is what happens:
I added some changes
I did not stage anything yet, so no git add . was issued
I do git status and I see lots of files as if they got modified and staged by me even though I did neither modified nor staged them.
For example, git status shows my .gitignore file now as:
me$ git status
On branch my-feature
Your branch is up to date with 'origin/my-feature'.
Changes to be committed:
new file: .gitignore
On Windows, this does not happen and since I did not modify this file, it will not show in git status at all. My modified files show as needed to be added which is how it should behave.
Why would files I never touched be viewed by git on Mac as somehow modified and staged?
In mixed dev environments (like I work in also) I see this behavior when 'line endings' are mismatched. The best way to solve this is to update your .gitconfig file.
I encourage everyone on the teams I work within to add the following to their .gitconfig file. You can add a .gitconfig to each repo, just like a .gitignore, and/or each developer can set it within their git global config file.
[text]
eof=lf
There are different options, but the key is for the whole team to use the same line endings when committing & pulling.
Here is my gitconfig, per the request below.
[User]
name = Ben Horgen
email = xxx#xxxxxxxx.com
[text]
eof=lf
[core]
autocrlf = input
[pull]
rebase = true
[push]
default = simple

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!

Configure git to be accessed in my network from portable HDD under Windows

I need to have a portable git setup in order to access a git repository in my LAN from a portable HDD, including the computer where the HDD is connected, under Windows. The HDD might be moved from time to time between the computers in my network. I wish to avoid SSH for the moment.
I have installed the portable version of the git, I have made a batch to set the PATH to the requested directories specified in the documentation before running git-bash or git-cmd.
I see it runs, I have made a bare repository, let's say in a path like m:/repo.git. Then, I got stuck as I don't know how to configure the remote in order to do the first push as `git push repo master' from my project path.
I think I should do a 'git remote add repo ' but I fail to set the correct URL or something. I am aware I should change the URL each time the HDD is moved or change the remote.
What are the correct setup steps?
Then, I got stuck as I don't know how to configure the remote in order to do the first push as `git push repo master' from my project path
Let git create that setting for you:
git clone m:/repo.git
cd repo
git --work-tree=..\myproject add .
git commit -m "first commit"
git push
That will import the files of your project in a local repo, which will be able to push back to your bare repo on M:\.
UNC paths are supported too
git.exe clone "d:/dev/SDK" "//comp1/Proj/git/SDK/"

Resources