How to pull changes on remote clone - linux

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.

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.

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

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

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

How to clone git repo from Windows to Linux?

I previously kept a bare git repository on a Linux server and a working copy in my local Windows laptop for development (syncing to the server using TortoiseGit over ssh). The server version was deleted/lost so I want to recreate the repo on the server using the latest commit from the local working copy on the Windows machine.
What is the best way to create this new remote bare repo copy on the remote Linux server from the Windows working copy?
You can re-create the linux server repo using
mkdir -p myrepo.git
cd myrepo.git
git init --bare
On the local copy, assuming the remote URL is the same, do
git push origin <branch refspec>
for example
git push origin master
Note: If the remote URL has changed you can use
git remote set-url origin <new-url>
Just create the repo on the server, then add the repo to your local one as remote if it is not the same location as before and push to it.
Follow these steps:
Create a bare repository on remote.
I guess the answer provided by ad22 is good enough for you:
mkdir -p myrepo.git
cd myrepo.git
git init --bare
Otherwise, you need to find out how to create a bare repository on server.
Copy or Memo the URL of that just created bare repository.
(Of cause, you need to have the right for accessing the URL.)
Add a new remote for your local repository.
Since you already have a local repository,
Right click in that repository, Click TortoiseGit -> Settings,
Give the remote a shortname and URL you copied
Add it and apply the setting.
See:
Push to remote by right clicking in local repository and click Push item.
In Push dialog,
Select the remote you just added.
Check the Push all branches checkbox if all branches can be public, otherwise you need push each branch one by one.
Check the Include Tags checkbox if you want to push all tags.
Suppose that's all. ^__^
On your Windows machine:
git clone --bare /path/to/local-working-copy-of-the-repo
The above command will create local-working-copy-of-the-repo.git folder.
Now copy the folder(bare repository) on to the Linux server.
Hope this helps.

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 ;)

Resources