how to add existing non-git project to bitbucket - bitbucket

I created a project using angular cli. Project is in directory dw-ng2-app and it has several files generated by angular cli. I want to create a Bitbucket repository for this. My confusion is, when I create a repository in Bitbucket, it gives me 3 options
I create a README and .gitignore file. I cannot use this option as
then when I try to sync the local project with repository, I get
error that there is no common history
I selected option of starting
from scratch. The web page listed the commands I should run to clone
and upload, eg git clone git#bitbucket.org:username/angularcli.git
but this creates a new directory on my local machine named
angularcli which has .git directory. I am not sure if I can use this
option as my project is in different directory and moving it to
angularcli directory might affect it (not sure)
3rd option is to
mention that I have an existing project. Then I am prompted to use
the command git remote add origin
ssh://git#bitbucket.org/username/angularcli.git but that doesn't
work as my current project directory is not a git repository
How can I move the angular cli project to bitbucket? Should I have created the repository first and then created angularcli project in the generated directory?

There are a couple of ways to do this, but the simplest may be to simply make your current project directory, a git repository.
Go to your project directory
cd dw-ng2-app
Initialize git repository
git init .
Add your current project to be tracked
git add --all
Make your initial commit
git commit -m "Initial commit for Angular project"
At that point, you can use the third, "existing project" option within BitBucket.
After you've created a new repo there, you can see its URL and use that to track your new repository with your local one
git remote add origin https://username#your.bitbucket.domain:7999/yourproject/repo.git
git push -u origin master
[Here's a complete writeup from BitBucket if you need.][1]
note - I used git add . originally in my example, and BitBucket recommends git add --all. Either of these will work fine in your case.
[1]: https://confluence.atlassian.com/bitbucketserver/importing-code-from-an-existing-project-776640909.html

If you've created project using angulat-cli then it automatically created project with git initialisation. It also commits initial changes locally.
So you just have to add remote origin and push the content.
-If repository is not initialise as git repository then:
cd dw-ng2-app
git add --all
git commit -m "commit message"
git push -u origin master
-If already initialise with git repository.
First of all go to directory dw-ng2-app : cd dw-ng2-app
add remote to your repository.
git remote add bitbucket https://username#your.bitbucket.domain/yourproject/repo.git
push the changes:
git push -u origin master
here's master is name of branch in which you want to push the content.

Related

Integrate Projects in a single project

I have same xcode project on two deferent macbooks with different code.we need to merge that code but we are not using any git account.We need to merge same file as well,I mean we have same viewcontroller and added two people add a code in single view controller How i can merge it.
For example:
I have a view controller Name "XYZ"and Person 1 added "Login Method"
into "XYZ" and person 2 added "Sign up Method" into XYZ. and both code
are on deferent macbook without any git account how I can merge
that.
Since you use the git tag, I will provide the way to do version control by git.
First, please sign up account for bitbucket (free for private repository) or github (only free for public repository). And create a repository. They are as the remote git repository(repo).
Then use git bash for local repository.
In one macbook, use these steps:
git clone <URL for your bitbucket or github repo>
cd reponame
copy your xcode project in reponame folder
git add .
git commit -am 'code version from first macbook'
git push
Now the code in the first macbook is pushed in your remote repo.
In the other macbook, use these steps:
In an empty folder, use git init
copy your xcode project in this folder
git add .
git commit -am 'code version from second macbook'
git remote add origin <URL for your bitbucket or github repo>
git pull origin master
Now the code from macbook1 is merging in macbook2
If there has conflict files, you should check and save them, and then use git add . and git commit -m 'solve merge conflict'.
Now this is the version that you merge the different macbooks together. You can push the version in remote repo by git push.
More git related, you can refer git book.
Any version control system comes to handy in this kind of situations. Merging manually is the option available other than version control system. Either merge using version control system like git or manually merge the files which is very hard to workout.

Split up Git Repository

I have a git repository that contains two directories:
src: A full Rails app
devbox: Files to build a vagrant machine and provision using an Ansible script
I wish to split these out to two separate repositories so I have one solely containing my app and another containing the vagrant devbox.
This SHOULD allow me to add the app repo as a git submodule inside the devbox one in order to be worked on but at the same time allow Capistrano to grab the source from the app repo without any faffing around to only get a subdirectory of the full combined repository.
Any thoughts about how to go about splitting the current repo up? I'm just a bit unsure where to begin.
move the devbox folder out of the repo.
mv devbox ~/Projects/
move the src folder out of the repo.
mv src ~/Projects
create two empty repos on your github account for both devbox and src
initialize devbox as git repo cd ~/Projects/devbox && git init
Add the git remote. Instructions provided when you created the git repo on github. git add remote ...
Push the repo to github git commit -am'initial commit' && git push origin master
Repeat steps 4-6 for src

Use Unused Repo for New Project

I would like to save my app in one of my unused repository in GIT. Instead of creating new repo and deleting old unused repo, i want to get knowledge about Git by use the unused repo for new project.
Ex:
old Proj repo name: app_old
new Proj repo name: app_new
Status of app_old:
Am deleted all files in app_old through command. Then check out the app, the downloading status gives 80 mb done. But, there is no files in downloaded folder.
Status of app_new:
Created a new iOS project without checking the “Create Git Repository” option. Then choose the option “Create Working Copy” in Source Control. Then add the remote of app_old in both Xcode Preferences and Configure in Source Control.
Please adjust my English!!!
There is not too much sense to reuse existing repository as you're going to delete it anyway.
However, in case of some constraint like reusing existing remote repo, there is a way to remove full history of git commits and start from scratch:
# create new branch named newProject
git checkout --orphan newProject
# do copy your new files here, set up project, set up .gitignore and things like that
...
# add all files to the project
git add -A
# commit the new branch
git commit
# delete the old master branch
git branch -D master
# rename current branch (newProject) to master
git branch -m master
# push back to origin
git push -f --set-upstream origin master
This way you'll get rid of old history and start from scratch with your new project.
As written in comments, you'll need to delete remote branches too if you got any.
OK, let's start from scratch. Create a new, empty directory and do:
git init .
git remote add origin <url of the existing repository>
git push origin :master
echo "Some text" > somefile.txt
git add .
git commit -m "Initial commit"
git push origin master -u
Note the colon in the third step. Also note that if you have any other directories pointing to the old repo, you will want to delete them and re-clone from the repo.

Add project files from Local machine to Github Repository

I am working on an iOS project. our employee has created a repository say app and we have a master branch by default. employee has created another branch say "second" now I need to upload my project files from my machine to Github repository's Branch "Second" looking into a lot of tutorial and didn't understood what and how to do that... This question may have already asked but sorry didn't helped any...
At first, make full backup of your project, so
you can restore it if something goes wrong.
If you have local git repository (in terminal you can see .git and .git**** files after execute "ls -la" command in project directory):
1) Open your project folder with your local git repository in Terminal and add your Github repository as origin:
$ git remote add origin https://github.com/your_user/your_repo.git
(This url you can see at Github repo)
2) Push all your local branches onto repository:
$ git push --all origin
If you do not have local git repository:
1) Create new folder, go inside it and in Terminal execute this:
$ git clone https://github.com/your_user/your_repo.git
2) Copy all your iOS project (with inner files/folders/etc) into that folder
3) Add all your local files into local git repo:
$ git add .
4) Commit all changes:
$ git commit -m initial
5) Push all your local branches onto repository:
$ git push --all origin
Also see Github help:
https://help.github.com/articles/adding-a-remote/
https://help.github.com/articles/pushing-to-a-remote/

How to upload a project to GitHub

After checking How can I upload my project's Git repository to GitHub?, I still have no idea how to get a project uploaded to my GitHub repository.
I created a repository and want to upload my project to it.
I've looked on the repository page for an upload button of some kind, but I haven't seen anything of the sort.
I've looked at the links provided so far, but I'm still getting nowhere. They mention command line; is that Windows command line or Git Bash? Because I can't get either to do anything.
I also tried using the Git GUI, but when I select the folder I want it says that it's not a Git repository...does it need to be zipped up? I tried adding the .gitconfig file in the folder, but it doesn't make a difference.
GitHub released a native Windows client which makes all the below steps redundant.
You can also use Sourcetree to get both Git and Mercurial setup on Windows.
Here is how you would do it in Windows:
If you don't have Git installed, see this article on how to set it up.
Open up a Windows command prompt.
Change into the directory where your source code is located in the command prompt.
First, create a new repository in this directory git init. This will say "Initialized empty git repository in ....git" (... is the path).
Now you need to tell Git about your files by adding them to your repository. Do this with git add filename. If you want to add all your files, you can do git add .
Now that you have added your files and made your changes, you need to commit your changes so Git can track them. Type git commit -m "adding files". -m lets you add the commit message in line.
So far, the above steps is what you would do even if you were not using GitHub. They are the normal steps to start a Git repository. Remember that Git is distributed (decentralized), meaning you don't need to have a "central server" (or even a network connection), to use Git.
Now you want to push the changes to your Git repository hosted with GitHub. You do this by telling Git to add a remote location, and you do that with this command:
git remote add origin https://github.com/yourusername/your-repo-name.git
*Note: your-repo-name should be created in GitHub before you do a git remote add origin ...
Once you have done that, Git now knows about your remote repository. You can then tell it to push (which is "upload") your committed files:
git push -u origin master
Follow these steps to upload a project to GitHub:
git init
git add .
git commit -m "Add all my files"
git remote add origin https://github.com/yourusername/your-repo-name.git
Upload of project from scratch require git pull origin master.
git pull origin master
git push origin master
git push --force origin master
if you have problems uploading!
Here I explain how I did it on Windows.
Make sure to install Git and GitHub.
After installation is complete, open Git Bash.
So a window like below is going to pop up:
Go ahead and type cd ~ to make sure you are in the home directory. You can check the address that you are in it by typing pwd;
Now you need to create a GitHub account. After creating a GitHub account, go ahead and sign in.
After you signed in, on the top right click on the + and choose “New Repository”
Then in the opened window, type the name that you wish to have for the repository in the “Repository name” box. Add “Description (optional)” if you like, and mark “Initialize this repository with a README”. Then click on “Create repository”.
Now go to your C drive; create a new folder and name it “git”. Now go to the “Git Bash” window; change the directory to c drive by typing cd ~; cd /c.
If you type ls there it would show you the folders there. Make sure it shows the Git folder there:
Now go back to the browser; go to your GitHub page, click on the repository that you made, click on “Clone or download”, and copy the address that shows there (by choosing copy to clipboard).
Now going back to “Git Bash”. Use the command cd git to go to the git folder; now write the following commands to connect to your GitHub (enter the username and password of your GitHub when it asks you):
git config --global user.name "Your Name"
And then: git config --global user.email youremail#domain.com.
Next type: git clone (URL), instead of the (URL), type the address of the GitHub repository that you copied from your GitHub page; (e.g., git clone https://github.com/isalirezag/Test.git).
Now if you do ls command you will see your repository there. If you also open the Git folder that you have in your window you will see that your repository is added as a folder.
Now use the cd command to go to the repository: cd Test
Go ahead and copy and paste any files that you want to put in this repository in that folder.
In order to transfer the files to your repository you need to do following now:
Type git
add filename (filename is the file name that you want to upload) or you can type the command below if you want to add all the files in the folder:
git add .
Then type: git commit -m "adding files". And then: git push -u origin master .
And then you should be all set. If you refresh your GitHub account, the files should be there :)
Follow these steps to upload your project to GitHub:
git init
git add .
git commit -m "Add all my files"
git remote add origin https://github.com/yourusername/your-repo-name.git
Upload of the project from scratch requires git pull origin master.
git pull origin master
git push origin master
If any problem occurs in pushing, use git push --force origin master.
Follow these two steps:
Create the repository online using the link: https://github.com/new
Then link your local repo to the remote repo using the command: git add remote origin https://github.com/userName/repo.git
Here the repo.git will be your newly created remote repo.
This will work like a charm. No need to worry about the SSH or HTTPS ways. I first faced the same issue and spent hours for solution.
But this worked for me.
Easy-to-follow steps: git pull origin master or main will give a fatal error:
Couldn't find remote ref main
So below steps will work just fine.
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/yourusername/your-repo-name.git
git branch -M main
git push -u origin main
This worked for me;
1- git init
2- git add .
3- git commit -m "Add all my files"
4- git remote add origin https://github.com/USER_NAME/FOLDER_NAME
5- git pull origin master --allow-unrelated-histories
6- git push origin master
Create a new repository on GitHub. To avoid errors, do not initialize
the new repository with README, license, or gitignore files. You can
add these files after your project has been pushed to GitHub. Open
Terminal (for Mac users) or the command prompt (for Windows and Linux
users).
Change the current working directory to your local project.
Initialize the local directory as a Git repository.
git init
#Add the files in your new local repository. This stages them for the first commit.
git add
# Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'. Commit the files that you've staged in your local repository.
git commit -m 'First commit'
#Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL. At the top of your GitHub repository's Quick Setup
page, click to copy the remote repository URL.
In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
$ git remote add origin remote repository URL
# Sets the new remote git remote -v
# Verifies the new remote URL Note: GitHub for Windows users should use the command git remote set-url origin instead of git remote add origin here. Push the changes in your local repository to GitHub.
$ git push origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin.
Source attribution: Adding an existing project to GitHub using the command line
I assume you are on a Windows system like me and have Git installed. You can either run these commands by simple command prompt in the project directory or you can also use Git Bash.
Step 1:
Create a repository in Git manually. Give it whatever name you seem fit.
Step 2:
Come to your local project directory. If you want to publish your code to this new repository you just created, make sure that in the projects root directory there is no folder name .git. If there is, delete it.
Run command git init.
Step 3:
Run command
git add .
Step 4:
Run command
git commit -m YourCommitName
Step 5:
Run command
git remote add YourRepositoryName https://github.com/YourUserName/YourRepositoryName.git
Step 6:
Run Command
git push --set-upstream YourRepositoryName master --force
Please note that I am using the latest version of Git at the time of writing. Also note that I did not specify any particular branch to push the code into so it went to master. In step 6 the Git will ask you to authorize the command by asking you to enter username and password in a popup window.
Open Git Bash.
Change the current working directory to your local project.
Initialize the local directory as a Git repository: $ git init
Add the files in your new local repository. This stages them for the first commit: $ git add .
Commit the files that you've staged in your local repository: $ git commit -m "First commit"
At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
In the Command prompt, add the URL for the remote repository where your local repository will be pushed : $ git remote add origin remote repository URL
Push the changes in your local repository to GitHub: $ git push origin master
First you have to create an account on GitHub
Then create a new project - name that project as you want and then your project URL is shown
Now copy the URL
Then open a Command Prompt and go to the directory or folder which you want to upload using cmd
Then type the following commands
git init
git add .
git commit -m "initial commit"
git remote add origin PASTE URL
git push -u origin master
Now check your GitHub account. The repository is successfully uploaded.
For complete guidance, you can watch this video.
It took me like 1-2 hours to realize that I'm supposed to create the repository at GitHub before trying to push my local files to GitHub (or whatever, Git service you're using).
After trying to push, errors were like:
remote: Repository not found.
fatal: repository 'https://github.com/username/project.git/' not found
I feel like an idiot, but I really would like to emphasize this for beginners like me. I just thought that my repository will be created automatically during the first push. I was so wrong.
You can see your remotes with this command:
git remote -v
Steps to upload project to Git:
Step 1 - open cmd and change the current working directory to your project location.
Step 2 - Initialize your project directory as a Git repository.
git init
Step 3 - Add files in your local repository.
add .
Step 4 - Commit the files that you've staged in your local repository.
git commit -m "First commit"
Step 5 - Copy the remote repository URL.
Step 6 - Add the remote repository URL as origin in your local location.
git add origin copied_remote_repository_url
Step 7 - Confirm your origin is updated or not.
git remote show origin
Step 8 - Push the changed to your GitHub repository
git push origin master.
I think the easiest thing for you to do would be to install the Git plugin for Eclipse. It works more or less the same as the Eclipse CVS and SVN plugins.
Make sure that Git is installed on your system. I'm explaining the process using windows OS [Although it shouldn't be OS dependent job]
Here is how I did:
Open the cmd (you can do with git bash as well if you've installed git bash).
Go to your project directory (where your project is located, it's essentially changing to directory either usiing cd path or through manual folder navigation).
Now type git init. This will initialize an empty repository if it is first time and Enter.
For example: git init
Now type git add <filename>(if specific file) or git add <filename1> <filename2> <filenameN> (if specific but more than one files) or git add . (if you want to add all files) and enter.
Now type git commit -m "commit message goes here" and enter.
(in case if you need to check the status you can do by typing git status) and enter.
Now type git remote add origin git_repository_url
(check git remote -v go check remote repository) and Enter.
Now it's turn to push it to the remote repository [essentially taking all the changes from local git to cloud(github) ...git push origin master and enter
(if you get error you push it forcefully by typing ...git push -f origin master and enter.
NOTE : master is the name of your master branch. If you've multiple branches, make sure that you select the name of the branch accordingly.
Now you're done with adding it to your remote repository from local computer. Refresh it and it will be there in your created repository's selected branch.
Probably the most useful thing you could do is to peruse the online book Pro Git. It's really a pretty decent read and gives you the conceptual context with which to execute things properly.
Follow the instructions from RishiKesh Pathak. You can even short the push command by inserting this command line one time only:
git config --global push.default simple
So next time instead of using git push origin master you just need:
git push
See details here.
Download Sourcetree.
It is available for Windows 7 (and later) and Mac, and it is highly recommended to upload files on GitHub via the interactive UI.
The best way to use Git is to actually start Gitting. Try out this website which makes you go step by step on what are the essential ways for performing functions on command line for pushing a project on GitHub.
This is called try.github.io or you could also take up a course on Codecademy.
I did as follows;
git init
git add .
git commit -m "Your_message"
git remote add origin #your_git_repository
git push -u origin master
Of course you have to install Git.
We need Git Bash
In the Git Bash Command Section:
ls
It will show your default location.
CD "C:\Users\user\Desktop\HTML"
We need to assign the project path.
git init
It will initialize the empty Git repository in C:\Users\user\Desktop\HTML
ls
It will list all file names.
git remote add origin https://github.com/repository/test.git
It is your https://github.com/repository/test.git is your repository path
git remote -v
To check whether we have fetch or push permission or not
git add .
If you use . then it means whatever we have in the particular folder publish all.
git commit -m "First time"
git push -u origin master
Upload a project from Visual Studio Code to GitHub
To upload your project in GitHub using Visual Studio Code, follow the following steps.
Open the Visual Studio Code. if you don't have the VSCode download: Download Visual Studio Code
In VSCode go to File-->Open Folder..
Go to Terminal-->New Terminal
Execute the following commands one by one after one another in order
git init
git add .
git commit -m "First Commit"
git remote add origin https://github.com/yourusername/your-repo-name.git
git push origin master
Note: in the above command git remote add origin https://github.com/yourusername/your-repo-name.git please change the bold sections with your GitHub account name and your repository name.
You need an SSH connection and GitHub init into your project. I will explain under Linux machine.
Let's start with some easy stuff: navigate into your project in the terminal, and use:
git init
git add .
git commit
Now let's add SSH into your machine:
use
ssh-keygen -t rsa -C "your_email#example.com"
Copy the public key, and then add it to your GitHub repository:
Deploy keys -> add one
Back to your machine project, now launch:
git push origin master
if there is an error, configure your .github/config file by
nano .github/config
And change the URL to the SSH one by:
url = git#github.com:username/repo....
And that's it.
Try using Git Bash to push your code/make changes instead of uploading files directly on GitHub (it is less prone to errors and is quite comfortable at times - takes less time as well!). For doing so, you may follow the below given steps:
Download and install the latest version of Git Bash from here.
Right-click on any desired location on your system.
Click “Git Bash Here”.
git config --global user.name “your name”
git config --global user.email “your email”
Go back to your GitHub account – open your project – click on “clone” – copy HTTPS link.
git clone PASTE HTTPS LINK.
A clone of your GitHub project will be created on your computer location.
Open the folder and paste your content.
Make sure content is not empty.
Right-click inside the cloned folder where you have pasted your content.
Click “Git Bash Here” again.
You will find (master) appearing after your location address.
git add .
Try git status to check if all your changes are marked in green.
git commit --m “Some message”
git push origin master
You just need to know few command im cmd to push or pull any directory to/from github.
Command to push/upload any project or code to the git hub.
First reach to the working directory or project directory which you need to upload.
to check the correct working directory
ls
to initialize the git in the directory
git init
to the check that git init worked or not
ls -a //this command shows hidden files
Using above command you will find file added in you directory.
./ ../ .git/
the above is not a command you can skip it.
Now add the files of working directory to commit
git add .
then use commit command and name that commit for reference
git commit -m "Commit Name"
Before final step you need to go to the github website and create a new repository and copy the url of the repository
git remote add main https://github.com/username/repositoryName.git
now command to upload the directory
git push -u main
Note: the name "main" is the name that can be change as per user
For uploading a new project into Git (first you need to have the local code base of the project and the Git repository where you will be uploading project. In Git, you need to have your credentials).
List item
Open Git Bash
Go to the directory where you have the code base (project location)
cd to project location
cd ////**
Then here you need to execute Git commands.
git init
Press Enter then you will see something like this below.
The initialized empty Git repository in ://****/***/.git/, so git init will initialize the empty Git repository at local
git add .
Press Enter
The above command will add all the directories, subdirectories, files, etc.
You will see something like this:
warning: LF will be replaced by CRLF in **************.
The file will have its original line endings in your working directory.
git commit -m "first commit"
Press Enter. -m provided option for adding comment.
It will commit the code to the stage environment.
You will see some thing like this:
[master (root-commit) 34a28f6] adding ********
warning: LF will be replaced by CRLF in c*******.
The file will have its original line endings in your working directory.
27 files changed, 3724 insertions(+)
create mode 100644 *****
create mode 100644 *****
create mode 100644 *****
git remote add origin
http://username#git:repopath.git
Press Enter. This will add to the repository.
git push -u origin master
Press Enter.
This will upload all from local to repository in this step you need to enter password for the repository where you will be uploading the code.
You will see some thing like this below:
Counting objects: 33, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (33/33), 20.10 KiB | 0 bytes/s, done.
Total 33 (delta 14), reused 0 (delta 0)
To http://username#git:repolocation.git \
[new branch] master -> master
Branch master set up to track remote branch master from origin.

Resources