This seems like it should be a common issue, but perhaps I'm not searching for the correct terminology.
I just copied an old project on a remote server to my local machine using scp
. I created a new instance of a git repository using git init
and used git remote add origin ...
to create a new remote git repository on-line, which I pushed to. This is the projects first instance of being tracked by git.
I created a .gitignore file so not all the content was pushed to the remote repository and I also pushed some minor changes after the initial commit.
Now I wish to pull the repository to the original project on the remote server. It obviously has no .git folder. I want the changes to be pulled but keep the files listed in the .gitignore, so I can't simply wipe the directory and perform a clean git clone
.
I only have ssh access. How do I go about this?
Ok figured out a method that worked for me using ssh.
Copy the local projects .git folder to the project on the remote servers directory. You may have to copy to a folder with correct privileges then move the .git folder
scp /local/path/to/.git user@remote:/remote/path/to/temp/folder
Change the ownership of the .git and move it to the existing projects directory
chown -R www-data:www-data .git/
mv .git/ /var/www/....
Performing a git status shows the changed files and untracked files. In my case the 'changed' files were the old files I wanted to overwrite, and the untracked files where the files I specified in .gitignore.
So to 'revert' the files to the new versions in the branch (stored in the .git folder) and ignore the untracked files, I just did
git checkout .
This also added the .gitignore file, which I had to chown
too.
This was tested on a project with only a master branch, but I hope this helps people in the future. My terminology may be a little off describing the git processes but hopefully everyone gets the picture.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.