converting a local git folder as a remote repository - windows

sorry if my question is too naive. Here is what i am trying to do:
I want to create a local git repo (git init )-> i did that
I want to access the same form other machines using ssh -> stuck here
I have tried installing git bash , but i don't know how to configure ssh which is built in the git bash.
I did add a ssh config file using git bash and gave as my computername along with domain, since this machine is the server here.
In the git bash guide, they are adding the public key to github, i dont want that
In short i have created a git repository by 'git init .'
I want to access the same using other machines in the same domain using ssh
I don't know how to proceed further, Would anyone be able to help in this case ?

I'd create a --bare repository somewhere accessible via SSH and push, fetch, merge, pull to and from that repository by adding a remote origin to the ones you created.
Something like
/home/git $ git init --bare your_repository.git
/your/current/repository $ git remote add origin /home/git/your_repository.git
And from another machine
/client/path $ git init
/client/path $ git remote add origin user#server:/home/git/your_repository.git
/client/path $ git pull origin
Then
/your/current/repository $ git fetch origin
/your/current/repository $ git merge origin/master
/your/current/repository $ git push origin master
/client/path $ git fetch origin
/client/path $ git merge origin/master
/client/path $ git push origin master
That's just an example, the --bare repository can be anywhere.
Have a look here for pros and cons http://git-scm.com/book/ch4-1.html

Related

git clone "you appear to have cloned an empty repository" but it's not empty, pull says "couldn't find remote ref master"

I'm trying to set up a vanilla new separate repository for the first time with git 2.37.1 on two W10 systems using drive mapping but I can't find any answered questions that fit my case given my novicitry. :-) Sorry the format is messed up, I did 4 spaces in front of code but most code lines ignore that for some reason.
Spent hours looking at other similar questions, but they all seem to say that there are no commits in the remote repository I'm trying to clone, which is not true. There are lots of commits.
I created a git repository on System1 and it works.
git ls-tree --full-tree --name-only -r HEAD
shows all my files (with lots of commits)
git show HEAD
shows
commit 557...27d (HEAD -> master)
# and the diff between the latest and previous commit
And
git branch -a
shows
* master
No branches, no complexity, no nothing
I go to System2, and create my repo directory, cd into it, then
git init
git remote add origin s:/cap2office # that's my mapped System1 repository)
git pull origin master
I get: fatal: couldn't find remote ref master
git remote
I get: origin
git branch -a
shows nothing
git ls-remote
shows: From s:/cap2office
I also tried:
git clone s:/cap2office
and it says
Cloning into 'cap2office'...
warning: You appear to have cloned an empty repository.
I know I'm missing some trivial magic command, but can't figure out what it is.
You are not cloning a repository, you are trying to clone the working directory of a git clone.
The git repository is stored in the .git folder inside the working directory.
Try this:
git remote add origin s:/cap2office/.git
On system 2, instead of doing git init then git remote add and git pull, do just this:
git clone s:/cap2office/.git
or if you're in Git Bash, sometimes the colon does not work so you need
git clone s/cap2office/.git
Then you can cd to the folder where it was cloned and do the usual git status, git checkout, change stuff, commit, and push to the remote.

How can i upload a Spring Java project to GitHub so i can show my work?

I've tried through various ways, directly uploading the files wont work. I've tried through bash and nothing.
Do you have git installed?
# Create a new repository on the command line
#Go to Project Directory on your Computer, Open git Bash here
# run the following 1 by 1
git init
git add .
git commit -m "Comment here"
git remote add origin https://github.com/YourRepoPrefixHere
git push -u origin master
If you have a git profile and a repository you can take these simple steps to get it online:
Open a terminal and go inside the folder of the project you want to push to your git repository
Check if you are on the right git branch: git checkout
git add .
git commit -m "your messagge to commit"
git push origin -u "yourbranchName
If you have never set up your origin branch, you should add it before using it:
git remote add origin "github link"
To see if everything went well you can do a simple: git status.
I hope it will be useful to you my friend!

Local repository is not able to pull branch from remote repository

I have been using GitLab successfully with another onsite developer with small projects in C and MATLAB.
Working from home using a VPN I pushed a large LabVIEW program into a fresh project so I can work alongside another off site developer. The developer cloned the project and began work on a branch.
The issue is I have not been able to pull/fetch this branch. GitLab is showing the branches and commits that the developer has made.
I have not been long using git and so I may just be being stupid.
Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."
I have looked at this in particular but have not made it work, below are some of the things I have tried.
$ git remote remove somelongcode
fatal: No such remote: 'somelongcode'
$ git remote add origin
usage: git remote add [<options>] <name> <url>
-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=(push|fetch)]
set up remote as a mirror to push to or fetch from
$ git remote master --prune
error: Unknown subcommand: master
usage: git remote [-v | --verbose]
or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
or: git remote rename <old> <new>
or: git remote remove <name>
or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
or: git remote [-v | --verbose] show [-n] <name>
or: git remote prune [-n | --dry-run] <name>
or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
or: git remote set-branches [--add] <name> <branch>...
or: git remote get-url [--push] [--all] <name>
or: git remote set-url [--push] <name> <newurl> [<oldurl>]
or: git remote set-url --add <name> <newurl>
or: git remote set-url --delete <name> <url>
-v, --verbose be verbose; must be placed before a subcommand
________________________
$ git fetch origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
________________________
$ git reset --hard origin/master
fatal: ambiguous argument 'origin/master': unknown revision or path not `in the working tree.`
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
I can see the branch in remote. This is the most encouraging at least I can see the remote even if I cannot sync with my local repository
$ git ls-remote
From git#gitlab.com:group/project.git
somelongcode HEAD
somelongcode refs/heads/apploc
somelongcode refs/heads/master
As you can see locally I cannot see the branch
$ git pull
From gitlab.com:group/project
* branch master -> FETCH_HEAD
Already up to date.
$ git branch
* master
$ git remote show origin
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The structure of any git repo is the same wherever you go, you can check your local branches under the folder .git/refs/heads or by using the command git branch.
As for what's in the remote declared in your repo, you can see that in .git/refs/remotes/ or by using the command git branch -a and check the red colored lines.
Now to the subject at hand, any git repo needs to know the url and the name of whatever remote you're going to use, and you can use git remote to manage that. So if you want to list them use git remote,
to list Up and Down stream of each one use git remote -v, and
to add a new remote use git remote add <remote_name> <remote_url>.
The remote url is composed as follows if you are using ssh git#<server_address>:<name_space>/<repo_name>.git so it's composed of:
server address which if you're using gitlab is gitlab.com,
name space which is group as you mentioned, and lastly,
repo name which in our case is project but you still need the .git extension at the end of the url.
You can also copy the url from the gitlab interface by clicking on the clone button which will show you the url with ssh and another with https.
Now if you configured your remote correctly you will need to refresh your local repository with what's in the remote by using the command git fetch <remote_name> and that will download all the branches from the remote to your .git/refs/remotes/ folder, Then if you have a branch that's there and doesn't have any mirror branch in local (.git/refs/heads) you can create it yourself to be able to add other commits on top of it by using the command git checkout -b <branch_name> <remote_name>/<branch_name>.
Try the below
$ git remote add origin remote/repository/URL
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
Then
git pull origin branch_name
Hi #Yannoff and anyone else who looked at this. Thanks for you help. I think I tried nearly everything with Bash. I cloned the project on another machine and it all worked as expected. I then cloned it again on my machine and again everything worked fine. It was my original local repository that was causing the issues. I wonder whether working from home over VPN had an effect? Everything works now but not my original local repo.
However I am now clearer on how it all works with the help of the web links you gave me so it has not all been in vein!
*** I was not setting up the remote origin correctly see Yannoff's advice and the accepted answer for reasoning.***
Very good website - https://www.atlassian.com/git/tutorials
To synchronize your local repository branch list with the remote one, use git fetch
So your command should be something like:
git fetch somelongcode
Then you should have the up-to-date branch list :)

Migrating all branches of GitHub repo to new location sends just Master as each origin/<branch>

I was very excited to get multiple repos migrated, but then come to find out my branches are all of master. Any thoughts on my mistake? Here is my process to migrating, specifically from a GHE to a GH account.
git clone <GHE repository>
cd <repository name>
for remote in `git branch -r | grep -v '\->'`; do git branch --track $remote; done
git remote set-url origin <public GH repository>.git
git push -u --all origin
I am obviously attempting to track and migrate all branches, and if I am asking too much we can do one at a time if this is an issue fixing.
Attempting to simplify the steps, I used...
git push --all origin
and...
git push --mirror origin
With only master pushing to GitHub. --mirror did actually clean up the bad branches that duplicated master.
So after some investigation with the team, this looks to be a clean migration process if all agree...
git clone <orig repository>
cd <repository name>
for i in `git branch -a | grep remote`; do git branch --track ${i#remotes/origin/} $i; done
3) Change your local copies origin to new location
git remote set-url origin <new repository>
4) Push it to new repository (as mirror of old)
git push --mirror
Before I accept, I would consider modifications and a better practice if exists.

Git Bash Fatal:Could not read from remote repository

So I have a git repo set up on a linux machine and I typed
git remote add test git#*****.com:/opt/git/project.git
and then I did
git init
git add *
git commit -m 'Blah blah'
When I go to do
git push remotename
I get fatal:Could not read from remote repository.
I know it is a problem on my side, because my friend can on his arch linux machine. I have private ssh keys in a different folder then my git bash and then I have public keys in the git user home folder all set up. I don't know if I need to set up SSH keys somehow with git bash or something.
You need to add the upstream repo as a remote
git remote add remotename git#*****.com:/opt/git/project.git
And now do a push
git push remotename
PS : The step where you ran git add git#*****.com:/opt/git/project.git was meaningless, and should have thrown you an error ideally.

Resources