Linux to Windows repository pull and push - linux

Our entire code base at work is housed on an IIS Windows environment. My task was to
copy the code to our new Linux Ubuntu server and go through the code to make the changes necessary to get it to run on the Linux box. It took a couple months but it works. In the meantime, code updates were made on the productions Windows server to the code base by another developer. Now I have the task of pushing the changes to the Linux box so we can pull the trigger and run it live in the new environment.
PROBLEM:
When I performed a git push origin master I was thrown an error stating that I must perform a pull first. Upon diverging and running a git status it says I have `11 and 3 commits each, respectively. The problem is over the course of 2 months I can't remember all the changes made and something could come crashing down in the Windows environment and that can't happen even for a short time. I just need some advice.
I was wondering if it's possible to create a clone of origin master then push the changes to my local from the prod, merge the files and then upload to the Linux box since I can't push to the Linux now because of the needed pull.

When you do git pull, the changes in the remote origin branch are merged into your local origin branch. That is your "local clone of origin/master," so to speak. Inspect the state of your own master branch, and if everything looks right, then push your changes.
Run gitk --all before and after the pull, and you will see that the merge took place, but only on your system.

Related

Updating local repo everytime original repo is changed

I have a project running on a remote server. I cloned it into the server to run. Problem is everytime I make a change to the code via git, I have to go into the remote server delete the folder and clone it once again. How can it automatically detect a change in the repo and update it?
You're looking for what's called continuous deployment|delivery.
Since you're using GitHub, you may want to look at GitHub Actions. This is one of many mechanisms that are available.
You can configure Actions to trigger various actions (including building, testing and deployment of your code [to the Digital Ocean droplet]) every time you make a commit.

commit code over gitlab but my local code is not updated

I have checkout the code few days back (almost a month ago), now i have made same changes but my local copy of code (on my machine) is not updated with the latest code.
now i have to commit my code to team repository in a situation where my local code have some code changes as well as team repository also have some new code.
please help me in simple steps to resolve it.
Thanks !
When you make some changes in your code use the "commit" for updating your local repository, once you're ready to send those changes to the remote server you should "push" and your local commits will be added into the remote server.
Now you have your own version of the code different from the remote servers one so you should "merge" them. I recommend you creating a branch to clear the changes and then merge it with the master.
Using a tool like DiffMerge will make your life easier to merge code.

Bluej is not pushing changes to gitlab repository

another little issue with my current choice of IDE , Bluej. I have set it up to be able to share a project (namely to commit and push changes) using GIT,and specifically through a gitlab repository.
After the first couple of successful pushes and commits(two weeks ago), I changed some code today, tried to do exactly the same procedure, and alas, the button OK in bluej to actually push the changes, is not active!
I have checked connection by entering password, all looks fine. Also, commits are happening fine locally, but when I try to push them through the TeamWorks of Bluej, the OK button remains inactive.
ps: a restart of the program did not solve the issue.
In that case:
switch to the command-line,
go to your repository folder,
and do a git fetch + git status
That should show you why a simple git push is not possible (possibly because you need to pull first)

git workflow with multiple remotes and order of operations

I have a bare git repository that I use to push to and pull from on a linux machine (let's call the bare git repository remote originlinux). From my working repository that has originlinux as a remote I push and pull until finally I decide to put it on github. I add the repository for github on their web gui and add the remote repository on my working repository (let's call the remote origingithub) using the git remote add command followed by git pull --rebase, then git push (pull before push since I wasn't allowed to simply push to a newly created github repository without getting one of these: 'hint: Updates were rejected because the tip of your current branch is behind'. I figure this has something to do with their option to create a readme file). And here's the issue, after performing these steps, the originlinux repository is completely not synced with the origingithub repository even though they have exactly the same commits and were pushed to from the same exact working repository. Could someone please explain in good detail why this occurring and also what I could do differently to prevent this from happening without reordering how I create my remote repositories? It seems like the workflow or order of operations I'm using doesn't make sense in git land, but how else would you keep multiple remote repositories sync'd on one working copy?
Thanks!
The two repositories do not have the same commits.
When you did git pull --rebase, you rewrote the entire history of the project so that every revision contains that readme file. So every commit in the history will have a different SHA1 identifier.
There are a couple of ways that you may be able to recover from this.
First, you could revert the state of your local repository to match the state or your first (non-github) remote. This would eliminate the readme file that you created on github (you can copy that to some other location and add it back in to git later if desired), along with any changes that you hadn't pushed to the first remote (including changes that haven't been committed).
git reset --hard originlinux/master
git push -f origingithub
The -f option there causes the push to be forced even though that is removing some commits. This is something that should be avoided in general, but it is sometimes necessary such as in this case.
The other option would be to just do a force push to your first remote, accepting the new history caused by the rebase.
git push -f originlinux
If the three repositories that you mentioned are the only ones, it shouldn't matter much which of these methods you use. If there are other repositories you may want try to determine which version of the history is more widely known, and keep that version.

Syncing website files between local and live servers using GIT?

Say I have two web servers, one local development and one live.
Under SVN I would checkout the website files to my local webserver's public_html directory and also to the live webserver's public_html directory. I would then work on the files directly on the local server and commit any changes to the central repository.
When I'm ready for those changes to go live on the live server, I would SSH in and perform an SVN update.
Essentially I have two working copies, one on live and one locally, though other users may also have working copies on their local machines. But there will only ever be one working copy on the live server. The reason for this is so that we can just perform SVN update on live server every time we want changes to be published.
How can a simiar workflow be accomplished using GIT?
To model your current work flow almost exactly do:
Set up a git repo.
Clone the repo on the server and locally.
Work locally
git push to the git repo
ssh to server
git pull.
Another way to do it would be to set up a "production" branch in git, have a cron job that continually pulls this branch on the server, and then just merge and push to the "production" branch any time you want to publish your changes. Sounds like you need a more concrete branching strategy.
See: Git flow branching model && git flow cli tool
Good luck! This is a very solvable problem with git.
You might find this useful: http://joemaller.com/990/a-web-focused-git-workflow/
In your local working copy:
git push ssh://you#yourserver/path/to/your/wc
will push the commited changes in your local version to yourserver.
Having a setup that triggers automatically pulling like leonbloy and codemac suggested may seem like a good idea at first but it tends to be very fragile. I suggest a different alternative.
http://toroid.org/ams/git-website-howto

Resources