GIT hard reset all from local folder (overwrite only on localhost) - linux

I have some problems with my project so i need to pull all from master again.
When i type git pull it give me that is everything is all up to date, but i can see on my project that my project have some issues on my local.
How i can pull all from master, but i need to rewrite all files from master to my localhost?
Really important is that i need to rewrite files just on my local from master, because i work for company and if anything happen to project it will be my foul :)
I have tried with --hard too, but nothing changes.

To make your local master identical to its remote counterpart :
# let's save your local changes (if any)
git stash
# make sure to be on master branch
git checkout master
# let's save your current master branch (to allow for rollback)
git branch backup_old_master
# make sure to get last version of remotes
git fetch
# reset to remote version
git reset --hard origin/master

Related

Setting a local rep as a git and merging with an existing remote

I created a Git repository and worked on it for a while (kept both local and remote synchronized), then I had some issues with my disk quota and had to delete the .git of the local repository (so basically now it's not a git rep, just a normal folder).
I kept working on this version for a while without syncing with the remote. Now I'd like to set the local folder as a git and linked it with existing remote repository (as a new branch, perhaps). I was wondering which commands I should use?
Thanks!
You can try the following but I strongly encourage you to make a backup of your local repository first.
Once you've done it, try to:
Enter your local repository, placing you at top of it, that is: where your former .git repository used to be;
Reinit your repository running git init. This will recreate a new .git subfolder, without overwriting the files already in it. You won't have any local and initial commit neither;
Re-add the initial upstream remote source using git remote add origin <url to former remote repository>
Update remote states with git remote update. This will fetch back all previous objects as well as remote branch names;
Force creation of a local "master" branch pointing at where the remote branch is: git branch -f master origin/master. You need to force it because you have no existing branch nor initial commit;
This should have automatically set upstream branch, but if not, do it with git branch master -u origin/master
You now should be set on the branch, but since your index is empty too, it will show up as "deleted files" in git's status. You need to bring back the index to branch's state without touching working directory, which is exactly the default mode (aka "--mixed") of the reset command: git reset origin/master
Just run git status and git diff to compare the state of your work to last known state of your repository.

How to pull changes on remote clone

Good day,
On remote server I have:
repository /git/project.git
clone /individual/user/project/www (remote removed)
clone /alpha/project/www (remote is set)
clone /stable/project/www (remote is set)
On local machine:
clone MAMP/htdocs/project (remote is set)
I use sftp connection to /individual/user/project to see changes in real-time and merging data from /individual/user/project to /alpha/project/ and after testing to /stable/project/
Question is:
how can i by commit+push from local machine auto-update /alpha/project/ and then if everything is fine pull changes on /stable/project/
how can i use special branches to auto-update specific remote folders, e.g.:
by commit+push alpha branch auto-update /alpha/project/
by commit+push stable branch auto-update /stable/project/
how can i pull changes for /stable/project/ from my local machine
P.S. using Terminal, SourceTree, PhpStorm, gitolite
red Pro Git 1st Edition & Pro Git 2nd Edition
It’s really possible to pull from local repo/git server to a remote server. The most important thing is you need to create a bare repo on remote server by git init --bare.
More detail steps please refer git clone from local to remote
You can add remote to your local machine as below:
git remote add ind <URL for individual/project>
git remote add alpha <URL for alpha>
git remote add stable <URL for stable>
Then you can commit your local changes by git commit -am 'message'
Push local changes to individual,alpha and stable by git push ind && git push alpha && git push stable
If you want to pull changes to local, you can first check if it’s has remote-tracking branch by git branch -a. Such as if it list stable/master, so you can directly switch to it by git checkout stable/master.
If you want auto pushed to another repo, please refer here.

How do i add and sync my local git on server? What is bare repo?

I am using git from a long time but never set it up on server. Refereeing to this Git: move existing repository from PC to server, clone from server
I have initiate a bare repo on server but while adding origin in local
"git remote add origin server:path/to/repo" i have no idea what to add here. My site is getwalkwel.com and user is getwamld
Thanks
Origin is the name of a remote which is typically created automatically when you clone a repo from another repo. The origin reference in the cloned repo will be created to point back to the repo that was cloned from.
In your case, where the bare repo was actually created later from your working repo, you will create origin in your working repo to point back to your new bare repo.
This is done with:
git remote add origin /barerepo/fullname
If your bare repo is going to line on a different machine, then you need the URL to reach the repo instead of just a file path.
For instance, you might have myuser#myserver:path/to/repo
Bare repository in Git is a repository which only contains version control information only in fact this will not have .git sub-directory or any working files.
This kind of repository is helpful when you need to share or divide your work between few people for example in work environment you and your team mates are working on same project and you all need to see changes and all needs to do push to repository in this case this repository is more useful.
You can add the remote repository to local git repo
$ git remote add origin ssh://myserver.com/var/git/myapp.git
pushing to remote repository:
to push our local master branch to the origin's master branch. You can do that using the git push <target> <local> command.
$ git push origin master
click here for more information on how this works

Sync Git Up To Server

My git client is behind my git server by a couple revisions and a git push doesn't seem to work because I did something quirky:
I had a git server on a machine whose harddrive crashed. Luckily, I had a backup although the backup was a couple of months old. I then made a new server and placed the backup git files up on the server.
In the time between the crash, I had made changes to files and committed them to the server. I have, for example, 1.4.8.30 locally, but only 1.4.8.26 on the server. When I try to git push the changes to the master branch on the server, it thinks everything is up-to-date, even though I can see the server is behind.
How can I get these files up to the server? I am scared I am going to lose revisions, or that these two are not correctly synced now. Thanks!
With Git, you have the complete repository locally (in .git directory).
Therefore a "restore" procedure should be:
Create a new bare Git repo (on the server)
git init --bare new-one.git
change origin (on the client)
git remote rm origin
git remote add origin path-to-new-one.git
Push your local data to repo
git push --all
Note: This is gets more complicated if there are more than one users with different local commits. Hopefully, you do not need that ;)

How does Git know which repository to push to?

I'm a complete noob when it comes to version control, but I recently started using GitHub to host some of my projects. I blindly use the command git push origin master to push changes to either of the two repositories. I don't understand how Git knows which repository to push to. I use the same command to push to each. Does the directory I'm in have anything to do with it?
Thanks for clearing this up for me.
A word of advice, "blindly use"ing anything is a bad idea.
git has a system of remotes which allows to specify URLs and transports to repositories other than the one where you're working. git push origin master pushes the current branch to the remote called origin as the branch master. You have a remote called origin. This is created by default when you clone a repository from a URL.
git remote add origin http://abc.com/def/ghi.git tells git the url that remote 'origin' points to.
When you use git push origin master, you aren't pushing to two repositories - you are pushing to the master branch in your repository who's name (alias) is origin.
Think of it like this:
I'm pushing my stuff to origin which is my repository address. What am I pushing there? My master branch.
If you are new and set git up yourself through git init, you probably aren't pushing to two repositories. Run this command to see what your remotes are:
git remote -v
This will return something like (assuming you have a git hosting service like github):
blahblah git#github.com:yourGithubName/fileName.git (fetch)
blahblah git#github.com:yourGithubName/fileName.git (push)
git#github.com:yourGithubName/fileName.git is your repository address. Some addresses are prefixed by https:// .
Git repositories contain a .git directory that contains metadata about the repository. That's what Git uses to determine where to push your changes.

Resources