Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: how to set remote in existing repo

One question please

I have a project on git with differents branches:

Master Pre Dev ....

I've installed my project files in another server by FTP (not by git pull or git clone) ir order to create a dev enviroment.

The folder of the project in dev enviroment don't have a git repo. Can I set that this folder is a existing repo (dev branch) without do a git pull or git clone?

like image 514
Karmo Avatar asked Mar 16 '17 13:03

Karmo


People also ask

How do I push a code into an existing git repository?

At the top of your repository on GitHub.com's Quick Setup page, click to copy the remote repository URL. In Terminal, add the URL for the remote repository where your local repository will be pushed. Push the changes in your local repository to GitHub.com.

How do I add a remote to a specific branch?

The steps to follow in order to push new Git branches to remote repos such as GitHub, GitLab or Bitbucket are as follows: Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch.

How do I change my remote origin?

For example, let's say that you want to change the URL of your Git origin remote. In order to achieve that, you would use the “set-url” command on the “origin” remote and you would specify the new URL. Congratulations, you successfully changed the URL of your Git remote!


1 Answers

Go to your project folder. Add a remote origin with your existing repository URL.

$ git init
$ git remote add origin <existing-repo-url>
$ git checkout -b dev             # checkout a new branch 'dev'

You need to stash (clean working tree and save changes temporary box) your changes before pull the master. Stash the changes and Pull master branch changes/commits.

$ git add .
$ git stash save 'local changes'

$ git pull origin master         # pull 'master' into 'dev' branch

Now, retrieve/pop local changes from stash.

$ git stash apply                  # return the code that cleaned before 

$ git commit -m 'message'
$ git push -u origin HEAD          # push to remote 'dev' branch

Once all is ok then, clean the stash (optional).

$ git stash drop
like image 94
Sajib Khan Avatar answered Sep 28 '22 00:09

Sajib Khan