How can I add the contents of an existing folder to Git version control?
The tutorial here covers the case of making a directory and then adding source contents to it. I have some source code in a folder that is path dependent and don't want to move it.
So, how can I just go into my folder and make it a repository?
Final working solution using @Arrigo response and @Samitha Chathuranga comment, I'll put all together to build a full response for this question:
Create a new repository on bitbucket:
Press on I have an existing project:
Open Git CMD console and type command 1 from second picture(go to your project folder on your PC)
Type command
git init
Type command
git add --all
Type command 2 from second picture (
git remote add origin YOUR_LINK_TO_REPO
)Type command
git commit -m "my first commit"
Type command
git push -u origin master
Note: if you get error unable to detect email or name, just type following commands after 5th step:
User johannes told you how to do add existing files to a Git repository in a general situation. Because you talk about Bitbucket, I suggest you do the following:
Create a new repository on Bitbucket (you can see a Create button on the top of your profile page) and you will go to this page:
Fill in the form, click next and then you automatically go to this page:
Choose to add existing files and you go to this page:
You use those commands and you upload the existing files to Bitbucket. After that, the files are online.
I have a very simple solution for this problem. You don't need to use the console.
TLDR: Create repo, move files to existing projects folder, SourceTree will ask you where his files are, locate the files. Done, your repo is in another folder.
Long answer:
Tips: Clone in SourceTree option is not available right after you create new repository so you first have to click on Create Readme File for that option to become available.
You can init a Git directory in an directory containing other files. After that you can add files to the repository and commit there.
Create a project with some code:
Then, while inside the project's folder, do an initial commit:
Then for using Bitbucket or such you add a
remote
and push up:You also might then want to configure tracking branches, etc. See
git remote set-branches
and related commands for that.The commands are given in your Bitbucket account. When you open the repository in Bitbucket, it gives you the entire list of commands you need to execute in the order. What is missing is where exactly you need to execute those commands (Git CLI, SourceTree terminal).
I struggled with these commands as I was writing these in Git CLI, but we need to execute the commands in the SourceTree terminal window and the repository will be added to Bitbucket.