How can i git init in existing folder [duplicate]


How can i git init in existing folder [duplicate]



This question already has an answer here:



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?



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




1 Answer
1



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.


my_awesome_branch


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.


my_awesome_branch



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.


master



Hope it helps.



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



Resources:

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?