Added BitBucket repo as remote on GitHub - linux

I've just installed git on Ubuntu, now I want to work on my repo in BitBucket. I'm a little confused on how to do so. I can't do the following:
git remote add BitBucketRepo git#bitbucket.org:dir/file.git
As it returns the following error:
fatal: Not a git repository (or any of the parent directories): .git
It clearly is pointing to a git repo, so why is it lying to me?
Also, it is worth noting I am using SSH and I have successfully paired my GitHub account to my computer.

You need to run this command from a local git repository (a directory in which you have run git init or git clone) - otherwise git remote doesn't know which local repo you want to add the remote for.
It should be as simple as cd my-local-dir, where my-local-dir is the directory containing your local (cloned) git repository.
If you don't yet have the repo available locally:
git clone git#github.com:...etc... my-local-dir
cd my-local-dir
git remote add ButbucketRepo git#bitbucket.org...
git push -u ButbucketRepo master
This will clone your code from Github into the my-local-dir directory, add your BitBucket repo as a remote repository, push your code up to Bitbucket and set the local master branch to track the BitBucket remote's master branch.
Tracking means that commands that involve a remote like git push will automatically use the BitBucket remote's master branch. If you don't want that behaviour, skip the -u option.

Related

git push --mirror - internal server error

I have created a git repo using (GIT API) and initiated it with git init. (but no git add or git commit command) . when i try to use the git push --mirror , it gives internal server error.
I saw the following bug (100+ ref will give internal server error)
https://github.com/isaacs/github/issues/1253
even my repo got 500+ refs.
Do i need to use git add and git commit to push the repository to github with mirror command ?
when i do the git add and git commit on local repo, i can push the content.
I'm doing all those using the API, and is it possible to use git push --mirror without any git commit or git add commands?
When i go to the remote repo, i can see the GitHub quick setup page, asked to execute git add, commit etc...
my questions is how should i avoid that GitHub quick setup page,and push my contents to the remote repo without executing git add, or git commit ?
I don't understand what's your content.
If you have file and don't add them and don't commit, you have no content, as far as git is concerned.
You need to have at least a commit to push your repository, otherwise you're pushing nothing.

Cannot clone git repo inside existing checked out git repository

I am trying to clone my a git repository inside an existing checked out git repository and getting this failure. I've done this workflow before so I cannot figure out why it would fail now. Does anyone have any suggestions?
The git repository does exist and I can clone outside of the checked out repository in a different location
Let's say I do the following
1. cd <existing git repo clone folder>
2. git clone https://github.com/apache/cassandra
Cloning Git Repository of cassandra
Cloning into 'cassandra'...
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
What could be causing this error?
PLEASE NOTE - I DO NOT WANT TO ADD THIS REPOSITORY AS A SUBMODULE TO MY PARENT GIT REPO. I simply want to figure out how to clone the repository in an existing working folder checked out from git.
Have a look at git submodules This was designed exactly for this. You can find information and examples here: https://git-scm.com/book/en/v2/Git-Tools-Submodules
In your case, this might work:
git submodule add https://github.com/apache/cassandra
In order to change the submodule to track a particular commit change directory to the submodule folder and switch branches as normal.
cd submodule
git checkout -b some_branch origin/some_branch
or for some particular tag
git checkout <version_tag>
You will need to commit this change to update.
Your question sort of seems to be in conflict. You can't have a git repo within another git repo without using git submodules AFAIK.
What you could do is have a dir that is not a git repo, and clone both the repos into that dir (so don't put the repos inside each other).
You could also add the repository as a remote (using git remote add name_of_remote http://your/remote/here). Then you can checkout any branch from either repo in the same repository.
I usually do not like to use submodules. for this case I would do the following:
1) in the main repo .gitignore the folder path where you want to store the repo the path-of-cassandra-repo/* (to ignore it)
2) in the terminal execute git clone https://github.com/apache/cassandra.git path-of-cassandra-repo/ where "path-of-cassandra-repo/" the name of the folder you want git to store the repo.
3) you are ready to go... Happy coding.
Let me know if this works for you...

Can't find my git repository url

So I think I am confused - but for some reason I cannot push or pull to my git repository.
I have a linux web server and have a web folder in /var/www/bcs.net.nz/
I did a git init bcs.git in this folder (I have also tried .git)
and then I thought I could do git clone git#bcs.net.nz:bcs.git to clone it on the local machine or git push on the remote machine.
I have also added a git remote add origin git#bcs.net.nz:bcs.git on the remote machine.
After all of that I still cannot push and pull anything.
I am a bit stuck.
git add . & git commit -m "initial commit" work fine.
git clone git#bcs.net.nz:bcs.git would mean to clone a (preferably bare repo) which is in /home/git/bcs.git
You could initialize one there, (git init --bare /home/git/bcs.git), and add a post-receive hook (chmod 755 /home/git/bcs.git/hooks/post-receive) which will checkout the code in the live server folder
#!/bin/sh
git --work-tree=/var/www/bcs.net.nz --git-dir=/home/git/bcs.git checkout -f

How to add a git repository to Ubuntu server

I have a node.js project local in my computer, right now, I want to push this project to remote Ubuntu server. I have create a project.git on Ubuntu server, and pushed to it. Right now, I want to run this project on the server, but how do I access this folder, it's just a git directory. The process I am following is like below:
Ubuntu server:
mkdir /home/git/project
cd /home/git/project
git init
Local computer:
git remote add origin root#someserver.com:/home/git/project
git add .
git commit -am "Initial Commit"
git push origin master
It push succeed. Right now, I want to execute this node.js project and run it on the server, but how to turn this git repository to a folder, so I can cd into it and then node app.js after?
If you want to see the code on the server side, you should init the repository without --bare option or clone it somewhere else on the server.
Bare repositories store only git specific files.
UPDATE:
If you create a repository without --bare option, you can't push anything to that branch where your server is staying. Better solution is if you create a bare repository and clone it somewhere else on the server. Notice that, you should use there git pull command if you want to see your fresh code.

git post-receive checkout to remote machine?

If you add the following script as a hooks/post-receive hook to a bare git repository foo.git:
#!/bin/sh
GIT_WORK_TREE=/bar git checkout -f
then whenever someone pushes to the repository the current state will be updated in directory bar.
This requires bar and foo.git to be on the same machine.
What's the easiest way to modify it so that the checkout is made on a remote machine (say baz:/bar) ?
One way would be to:
#!/bin/sh
GIT_WORK_TREE=/tmp/bar git checkout -f
rsync ... /tmp/bar baz:/bar
Is there a better way? Perhaps not requiring an intermediate temp directory? (If not what are the correct options to pass to rsync such that the resulting directory is indentical to being checked out directly?)
GIT_WORK_TREE=/bar means that bar is a git repo.
If bar is a git repo on the remote side, then it can pull from a bare repo bare_bar.git (also on the remote side), to which you can push to.
In other words, your post-receive hook would push to bare_bar repo through ssh, and a post-receive hook on that bare repo would trigger the pull from the actual repo bar: see "Creating a git repository from a production folder".
I'd prefer a solution that keeps the remote server free of any .git dirs (and even the git package itself ideally)
In that case, your current post-receive hook and its rsync command seems to be the only way to incrementally copy new data to a remote working tree.
git archive would archive everything each time.
git bundle would require git on the other side.

Resources