Create git repository for existing project? - xcode

After a close call with deleting a swift file, I noticed that I did not have create the project with it to create a git repository. Is there a way to have an existing project start a git repository? Or do I have to start a new project and move all of my code/files over?

Yes, you can initiate a git repo for an existing project.
There are several ways to initiate and manage a Git repository over an existing project.
Preparations.
There are some files that are not subject to source control. Those are project files from your IDE, compiled classes and so on. To exclude them, get a .gitignore file and put it to the root directory of your project.
Creating a Git repo with command-line tool
go inside the project folder and create new git repository using:
cd path/to/your/project
git init
Then add your files
git add *
and then commit
git commit -am "Initial commit"
if you need to push it to GitHub/BitBucket use
git remote add origin [repository URL]
and then
git push origin master
Creating a Git repo with a gui-based tool or IDE.
You can as well use any gui-based tool. E.g., in IntelliJ IDEA use the menu [VCS] - [Import into version control] - [Create Git repository].
If you are going to use GitHub, there's a convenient GitHub client.

Related

Github how to push Xcode project without old files and folders?

I finished an Xcode project and pushed it to github from Xcode 'Source Control' Menu. Then I changed the project name CountryBook to Countries. I Built project and ran. Everything was okay. Then I coiped project folder to desktop as a backup. Then pushed project again. Everything has messed up. Some old named folders and files still exist in repo. Then I deleted every directory and file from github repository. Now, backup version of project is working. But when I try to push it to repo, old files are still exist. I deleted 'origin' from 'Remotes' and created a new repo named 'Countries'. I pushed project again but it was same. A mixed version of old files and new files. When I clone the github version of project, of course it is not runnable. What sould I do and how can I push clean version of my project? I don't want to lose project.
This is Countries repo now:
This is my working project folder with correct content:
I would fix it via command line, lets assume you start from scratch:
Step 1 - prepare the working branch:
Clone the project
Navigate to root folder of the project
Checkout the main branch ("main", "master", or whatever it is)
Create a new branch you will be working with
git clone https://github.com/yourorg/yourrepo
cd yourrepo
git checkout main # or master
git checkout -b fixprojectstructure # branch name can be anything
Step 2 - clean project locally
Delete old project, old workspace, ensure the names in Podfile and Podfile.lock are fine
Build the project and ensure it's working
Step 3 - commit your changes:
# assuming you are in the root of the project
git add .
git commit -m "Some explanation"
Step 4 - push your changes:
I usually do it the lazy way: just run git push, which will show you the proper syntax to push remotely, something like
> git push
fatal: The current branch fixprojectstructure has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin fixprojectstructure
> git push --set-upstream origin fixprojectstructure
Enumerating objects: ...
...
remote: Create a pull request for 'fixprojectstructure' on GitHub by visiting:
remote: https://github.com/.../pull/new/fixprojectstructure
remote:
...
Branch 'fixprojectstructure' set up to track remote branch 'fixprojectstructure' from 'origin'.
Step 5 - merge your changes:
Basically just do what the line above is saying:
Navigate to https://github.com/.../pull/new/fixprojectstructure
Create pull request
Merge pull request to main (or whatever the initial branch was)
Note on the side: configure the gitignore file properly for your repo as well. For starters, follow the gitignore template to create a proper gitignore file, and then change it the way you need to.
For instance:
Usually, if you use cocoapods, you do not store .workspace folder and its contents in the repo. Instead it's generated using pod install command on each machine that needs it.
It's also common to exclude Pods directory from storing in the repo, although there are pro / cons arguments both ways.

Uploading Files from Laravel App to BitBucket

Here is what im try to achieve, I have a laravel app with a BitBucket repo in my laravel project public directory (public/repo.name).
Now what i want is to run, git add . git commit -m "Changes" and git push from my (public/repo.name) directory inside my laravel app.
I want the git commands to run when i go to lets say, http://127.0.0.1:8000/deploy this would only deploy whatever changes are in (public/repo.name)
Convert your Project to a Git Project
Open your terminal and navigate to the project root directory and run the git init command.
git init
git-init-laravel-project
Git init Laravel project
Git Add and Commit All Files
With the git init command we have successfully converted our project into a local git project. Although we have not yet added a git remote to our project.
As a second step lets go ahead and add and commit all the files to our local git repository.
Run the git add and git commit command on the project root.
git add .
git commit -m "First Commit"
The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.
The git commit command commits the staged snapshot to the project history. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to.
Git add and Git commit on Laravel project
Create a New BitBucket Repository
We are now ready to push our changes to a remote repository. But before that we have to create a repository where we can push our changes.
Login to Bitbucket if you already have an account or SignUp for a new account. On the left hand menu , Click on the + symbol to get the option of Creating a New Repository.
Create Bitbucket empty Repo for Laravel.
Enter a suitable project name and click on Create Repository. A blank repository will be created and you will be redirected to the overview page of the repo.
Now we can go ahead and make this repo our remote repo for the Laravel project.
Add Remote Repo and Push Changes
To add the repository you just created as the remote repo for your local Laravel project. Run the following command on your project root in terminal.
git remote add origin https://<repo_owner>#bitbucket.org/<accountname>/<reponame>.git
Replace the repo_owner and accountname in the URL accordingly.
git-laravel-remote-add
git remote add laravel
Now we can go ahead and push the changes to remote repository.
git push -u origin master
git-laravel-push-bitbucket
Git push Laravel project
If you see at source in your bitbucket repository. You should see your Laravel directory structure along with the files.

How to start new Git from scratch when old Git still there

I want to create a new empty repository with git. I cannot find a simple solution online that explains this step.
This documentation states "git-init - Create an empty Git repository or reinitialize an existing one" but then doesn't say which options are needed to make it empty:
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-init.html
Is a --bare repository the same as an empty repository?
Problem:
I have two different projects with different repo's on github, but when I try to use Git (in Bash) after changing the directory to the new project, it keeps pushing with files from the old project.
I think the problem is that git is using the old repo files and thinks the new folder is just additional files perhaps? Basically I want to start from fresh. Can I just start from scratch on my new project with a new repo?
I have tried $ git init in a new directory, but then it just says: "Reinitialized existing Git repository in /home/user/new_project/.git/"
I tried: $ git remote set-url origin git#github.com:User/New_Project.git
but that just updates where it pushes my new project to, and then includes old projects files.
Please help a noob trying to figure things out the hard way 🙏🏼
Delete .git folder:
rm -rf .git
Then create new git repository:
git init
git remote add origin <remote-URL>
git add .
git commit -m "new clean repo"
git push --force origin master
create 1st project
make git init
create a remote repo for 1st project
link remote repo to 1st project
create 2nd project
make git init
create a remote repo for 2nd project
link remote repo to 2nd project
Git will push everything to its proper remote repo
Small hint from my side
git init : create empty repository and reinitialize an existing one
following link will give more information about different options can be used during git init ($GIT_DIR)
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-init.html

uploading code to github

I have created a repository named appengine-testers on github. It is a public repository. Though I easily managed to create a repository but I do not know how to store code there. Do I need to upload the code/folder ?
There are multiple options to do that, i'll just briefly tell the simple one.
git clone ssh-path-to-project
It creates .git folder in the project which is used for references.
cd project
copy the entire project code from any location and paste it in this folder.
Now
Add all the untracked files.
git add .
git commit -am <"commit message">
or
git commit -a
Which automatically takes the changes.Lastly
git push
It pushed the entire code to the repository
One more simple option is do
git init
in the project folder and then change the remote url in the .git folder created inside the project folder
Once you create the repo on github, it'll give you a URL (that looks kinda like git#github.com:yourusername/appengine-testers.git) with push access. From there, you just push from your local repo to that URL.
It's probably easier if you add that URL as a remote. Typically you'd call it 'origin'.

How to Set Up Xcode with Remote Git Repository

so I just installed a new remote git repository on one of our servers and want to move our old projects there. Our existing projects have local git repositories, and we can add repos from the server, but how do we move our existing projects onto the server?
Any ideas?
You would do these steps:
Make the individual repositories on the server.
git clone --bare nameofrepo
On the actual repo, add the remote to the repository from which you want to send up work:
git remote add origin <url to your remote>
Now push your branch for your work:
git push origin master
Repeat for any other branches you want to have pushed to the central repo.
The URL in the first command can also be a regular file path. Most solutions, however are through an SSH connection.
After creating your Xcode project, cd to that directory
and make sure you are on the master branch
Type:
git remote add origin <URL-of-your-GitHub-repository>
git pull
git branch --set-upstream-to=origin/master master
git merge
git commit -m "Merging with remote”
git push
Now your new project has been pushed to the remote GitHub directory.

Resources