The following commands can be used on a production server.
In the case of a local machine development, use free software like GIT DESKTOP / SourceTree
First deployment in a folder
git clone <URL GITLAB/GITHUB HTTPS>
Updating / Getting last changes
The following commands respond to particular problems that may arise.
Changing the URL of a GIT Repository
This problem can occur if you are using GITLAB or GITHUB with SSH and you want to switch to HTTPS or vice versa, or following problems with the rights of an SSH key such as “remote: The project you were looking for could not be found.” and “fatal: Could not read from remote repository.”
Checking the repository URL:
Changing the URL of the repository:
git remote set-url origin <URL>
You cannot pull the changes “You have unstaged changes”
You may get the following error, indicating that some files have changed and need to be committed when you haven’t touched anything and just want to update the server:
Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.
In order the solve this problem we should remove all the unstaged changes:
You can now use the git pull command.
Back to the previous commit
Back to a specific commit
git reset --hard <ID COMMIT>
The commit ID is usually 7 digits and hexadecimal letters, example:
You can find it in the history tab of your GIT DESKTOP
Overwrite changes on the distant repository (local > remote)
git push --force origin master
Caution, delete on the distant repository, useful if you want to “delete” a commit that has been pushed.
Overwrite changes on the local repository (remote > local)
git reset --hard origin/master
Caution, deletes all the changes made not pushed to the remote git, useful if you want to “delete” the commits locally to have the same thing as on the remote git.