github repo deleted. Now cloning local to a new remote repo

My current git repo has all the commits and branches and whatever that was done in the repo. Although the remote repo somehow got deleted long back. I now want to push the current repo to a new remote as it is. I created this repo to learn git so I made sure that all the commits and branches are also present in the remote back then. Now I wanna do it again. I am trying to understand reflogs of the repo so that I can compare what will go and what will not. Here are the reflogs below. I am stuck at the point that in the 3rd line, there's a branch name mentioned for the commit but only for the remote and not local branch. Can anyone clarify why is that?
$ git reflog
bf302bb (HEAD -> branch_a) HEAD@{0}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{1}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{2}: commit: more changes on the branch
0f3bdda (origin/branch_a) HEAD@{3}: commit: branch_a commit
bbe56be (origin/subbranch, subbranch) HEAD@{4}: checkout: moving from subbranch to branch_a
2c8ab12 (origin/brnch, brnch) HEAD@{5}: checkout: moving from subbranch to brnch
bbe56be (origin/subbranch, subbranch) HEAD@{6}: checkout: moving from main to subbranch
1c320e0 (origin/main, main) HEAD@{7}: Branch: renamed refs/heads/master to refs/heads/main
1c320e0 (origin/main, main) HEAD@{9}: checkout: moving from subbranch to master
bbe56be (origin/subbranch, subbranch) HEAD@{10}: commit: subbranch code
1c320e0 (origin/main, main) HEAD@{11}: checkout: moving from brnch to subbranch
2c8ab12 (origin/brnch, brnch) HEAD@{12}: commit: brnch code
1c320e0 (origin/main, main) HEAD@{13}: checkout: moving from subbranch to brnch
1c320e0 (origin/main, main) HEAD@{14}: checkout: moving from brnch to subbranch
1c320e0 (origin/main, main) HEAD@{15}: checkout: moving from master to brnch
1c320e0 (origin/main, main) HEAD@{16}: commit (initial): main branch
$ git reflog
bf302bb (HEAD -> branch_a) HEAD@{0}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{1}: reset: moving to HEAD
bf302bb (HEAD -> branch_a) HEAD@{2}: commit: more changes on the branch
0f3bdda (origin/branch_a) HEAD@{3}: commit: branch_a commit
bbe56be (origin/subbranch, subbranch) HEAD@{4}: checkout: moving from subbranch to branch_a
2c8ab12 (origin/brnch, brnch) HEAD@{5}: checkout: moving from subbranch to brnch
bbe56be (origin/subbranch, subbranch) HEAD@{6}: checkout: moving from main to subbranch
1c320e0 (origin/main, main) HEAD@{7}: Branch: renamed refs/heads/master to refs/heads/main
1c320e0 (origin/main, main) HEAD@{9}: checkout: moving from subbranch to master
bbe56be (origin/subbranch, subbranch) HEAD@{10}: commit: subbranch code
1c320e0 (origin/main, main) HEAD@{11}: checkout: moving from brnch to subbranch
2c8ab12 (origin/brnch, brnch) HEAD@{12}: commit: brnch code
1c320e0 (origin/main, main) HEAD@{13}: checkout: moving from subbranch to brnch
1c320e0 (origin/main, main) HEAD@{14}: checkout: moving from brnch to subbranch
1c320e0 (origin/main, main) HEAD@{15}: checkout: moving from master to brnch
1c320e0 (origin/main, main) HEAD@{16}: commit (initial): main branch
If you could connect with me and see it live. It would help more in this case.
42 Replies
JavaBot
JavaBot3w ago
This post has been reserved for your question.
Hey @theash2473! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st3w ago
ok so the reflog is a history of what happened locally so it tells you what changed/what you checked out/commit on your device For pushing all your local branches to a remote repo, you normally don't need the reflog if you run git push --all YOUR_REMOTE_HERE, it pushes all branches you have locally to the remote you specified
theash2473
theash2473OP3w ago
But will it have each and everything as it was before. The commits, branches, merges etc?
straightface
straightface3w ago
depends did you pull all commits, branches, merges etc? It will have everything that you have
theash2473
theash2473OP3w ago
See I was the only one in this repo. It was just a repo I created totest the tricks of git. So I have everything of it in my local.
straightface
straightface3w ago
then you are good
dan1st
dan1st3w ago
issues and PRs won't be included if you want tags, you can push them with git push --tags
theash2473
theash2473OP3w ago
What's that? I didn't create any tags before you ask.
dan1st
dan1st3w ago
tags are similar to branches if you don't have any tags, you don't need to worry about it
theash2473
theash2473OP3w ago
ok So you are able to understand the history of the repo from this log right? I'm gonna attempt what you said. How would I check if everything happened correctly?
dan1st
dan1st3w ago
only a part of it it's the history of what you did on that computer when that repo was checked out and typically only the latest things if you tell git to commit something or switch a branch, it's added to the reflog but entries from there will be cleaned up at some point
theash2473
theash2473OP3w ago
Yeah it says 30 days but I have these logs even after 2 years somehow.
dan1st
dan1st3w ago
yeah it isn't instantly deleted like if you don't do anything with the repo, it isn't deleted
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
theash2473
theash2473OP2w ago
No, the reflog. It is supposed to be deleted. IDK
dan1st
dan1st2w ago
it gets cleaned up when running certain git commands IIRC
When common porcelain operations that create objects are run, they will check whether the repository has grown substantially since the last maintenance, and if so run git gc automatically. See gc.auto below for how to disable this behavior.
https://git-scm.com/docs/git-gc that's what removes reflog entries except you remove it manually
theash2473
theash2473OP2w ago
Atlassian
Git Reflog Configuration | Atlassian Git Tutorial
Reflogs track Git refs updated in the local repository. In addition, branch tip reflogs, a special reflog is maintained for the Git stash. Learn more.
theash2473
theash2473OP2w ago
Check this link Twas 90 days not 30.
dan1st
dan1st2w ago
Did you manually run git reflog expire?
theash2473
theash2473OP2w ago
No never Just read this thing
dan1st
dan1st2w ago
then you shouldn't be surprised by these entries not being removed . git normally doesn't trigger it randomly if you aren't doing anything
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
theash2473
theash2473OP2w ago
Stack Overflow
Connect a local repository with a remote repository
I have a local repository. I created the whole application, but now I want to push it to a remote repository. I already have remote repo as well. How can I connect these two repositories without lo...
theash2473
theash2473OP2w ago
It suggests to use set-url instead. Will any of the two commands work?
dan1st
dan1st2w ago
git remote add --> adds a new remote, you'd need to push with the remote you added there, you cannot use this if the remote exists already git remote set-url --> updates an existing remote, you'd need to push to the updated remote, you can only use set-url if the remote exists
theash2473
theash2473OP2w ago
What is the use of git branch -M origin if I don't wanna change the names of any branches?
dan1st
dan1st2w ago
What? Do you have a branch named origin? Why?
theash2473
theash2473OP2w ago
No I don't have any but why do I need to change it? Shouldn't I just upload the repo as is? Also, why does it say in the documentation that -M moves/renames a branch? What does it mean by moving a branch? attaching it to another branch?
dan1st
dan1st2w ago
you said something about git branch -M origin which doesn't make sense
theash2473
theash2473OP2w ago
ohk ignore origin. Just talking about the command in a new github repo git branch -M main
dan1st
dan1st2w ago
I have no idea what you are trying to do
Manish Kumar
Manish Kumar2w ago
go to folder 📂 git init git remote add origin < new repo url > then commit -> then push
theash2473
theash2473OP2w ago
no need of renaming right?
dan1st
dan1st2w ago
idk why you would want that or where you have picked that up
theash2473
theash2473OP2w ago
In the page of a new repository it suggests that command before pushing. On GitHub
theash2473
theash2473OP2w ago
No description
dan1st
dan1st2w ago
you don't need that unless you want to change branch names
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
theash2473
theash2473OP2w ago
What is git remote add --mirror ? What does mirror do exactly?
dan1st
dan1st2w ago
When a fetch mirror is created with --mirror=fetch, the refs will not be stored in the refs/remotes/ namespace, but rather everything in refs/ on the remote will be directly mirrored into refs/ in the local repository. This option only makes sense in bare repositories, because a fetch would overwrite any local commits. When a push mirror is created with --mirror=push, then git push will always behave as if --mirror was passed.
theash2473
theash2473OP2w ago
I think I can ignore them then I haven't looked into bare repositories
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?