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

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.

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.

Laravel - bitbucket pull / push

I'm totally confused how I should add my laravel project to my bitbucket profile and repository. That project that I am adding should be used by me and my college colleagues and they all have to push their changes to the project. How it works ? And how can I pull those changes to my local project on my PC ?
Please help. Thanks!
This can be achieved by creating a repository on bitbucket. Then navigating to the project on your local environment and running the following commands:
cd my-laravel-project
git init
git remote add origin git#bitbucket.org:yourusername/my-laravel-app.git
git add -A
git commit -m "Initial commit"
git push -u origin master
Colleagues can then clone the repository using the following command:
git clone git#bitbucket.org:yourusername/my-laravel-app.git
cd my-laravel-app
after making changes they can be committed using:
git status
git add -A
git commit -m "Fix database connection"
git push
The changes made by colleagues can be retrieved using:
git pull
Merging can be achieved by first pulling the target branch into the current branch then comparing and committing the changes:
git pull origin master
// review the changes
git add -A
git commit -m "Merge changes"
git push

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 :)

How to do push for new repository?

I created new repository (git#github.com:derkode/ForvoClient.git) and did SSH Key, then:
git config --global user.email "my_email#mail.com"
git config --global user.name "my_nickname"
git config --global push.default simple
git init
git add *
git commit -m "First commit"
git remote add origin git#github.com:derkode/ForvoClient.git
But after: git push -u origin master
! [rejected] master -> master (non-fast-forward) error: failed
to push some refs to 'git#github.com:derkode/ForvoClient.git' hint:
Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git
pull') hint: before pushing again. hint: See the 'Note about
fast-forwards' in 'git push --help' for details.
What is it?
Your repo on GitHub already has a commit.
https://github.com/derkode/ForvoClient
This is normal when you create a repo with a README file.
You can fix this either by force pushing your local repo to GitHub, but you will lose the README file this way:
git push -u origin master -f
Or, you can merge the version on GitHub into yours and then push it back:
git pull origin master
git push -u origin master
Or, as #xbonez suggested, rebase your version on top of GitHub's version:
git fetch origin
git rebase origin/master
git push -u origin master
If you want to get rid of the commit that Github created for you with the README file, follow janos's answer. If you want to keep that commit, and push yours over it, simply pull down those changes and then push:
git fetch origin && git rebase origin/master && git push origin master

converting a local git folder as a remote repository

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

Resources