Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i git init in existing folder [duplicate]

Tags:

git

I have a git repository that contains folders and files. And have locally a same folder as in git but a little bit changed files but not connected to git. How can i connect my local folder to the same git and commit all changes that i have done?

like image 721
Grish Barseghyan Avatar asked Jul 01 '18 13:07

Grish Barseghyan


1 Answers

If your local folder is not a git repository, you should make it a repository first and commit your changes in a new branch then add a remote linking to your existing repository where you want to push your branch containing the changes.

$ cd path/to/your/local/directory
$ git init # make it a git repository
$ git checkout -b my_awesome_branch # checkout to a new branch containing your local changes
$ git add --all
$ git commit -m 'This should be a Message describing your local changes'

You will have all your local changes in git branch my_awesome_branch. Now, You need to setup an upstream to remote repository where you will want to push this my_awesome_branch.

$ git remote add my_awesome_upstream <your-upstream-git-repository-url>
$ git remote -v # To list remotes, and see if your remote is added correctly
$ git push my_awesome_upstream my_awesome_branch

Now, you can go to your remote repository and checkout to my_awesome_branch from the UI in order to see your changes.

To merge the changes into the main branch(e.g. usually master), you can open a merge/pull request against the main branch and review your changes before merging them to your main branch.

Hope it helps.

Let me know if any of the above is not clear. I will be in touch.

Resources:

  1. Adding an existing project to GitHub using the command line.
  2. Adding a remote
like image 69
mrehan Avatar answered Nov 02 '22 09:11

mrehan