0

I just created a new remote repository then added, committed and pushed all local repository files to this new remote repository.

git add -A
git commit -m "all files added"
git push newRepo master

Before I did this I was pushing to another repository while leaving most files untracked as well as not committing changes to most files.

> git status

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

Now my local repository is ahead of the oldRepo 2 commits and changes seem to be tracked between newRepo and the local repository. How can I revert back to tracking between the oldRepo and my local repo?

So there are 2 remote repositories: newRepo and oldRepo + my local repo I need to track between local and oldRepo.

el_pup_le
  • 11,711
  • 26
  • 85
  • 142

3 Answers3

1

To make a local branch track remote/branch, simply do

git branch -u remote/branch branch

Where branch defaults to checked out branch.

--set-upstream-to

pishpish
  • 2,574
  • 15
  • 22
  • i did: git branch branch_name --set-upstream-to your_new_remote/branch_name. but git status hasn't reverted i think i need to pull the remote changes now – el_pup_le Jul 13 '17 at 10:09
  • You used an incorrect syntax. It should be `git branch -u your_new_remote/branch_name branch_name`. – pishpish Jul 13 '17 at 10:11
  • it works, from here: https://stackoverflow.com/questions/4878249/how-do-i-change-the-remote-a-git-branch-is-tracking – el_pup_le Jul 13 '17 at 10:24
  • Yeah, my bad. Can you please specify exactly which branch is tracking which remote branch and say what you want to achieve? Your question is a bit unclear. – pishpish Jul 13 '17 at 10:33
  • each repo just has a master branch. I need tracking to revert to being to as it was before I added and committed all my files to my local repo. So by tracking between my old remote repo shouldn't I be able to revert to whatever was committed and uncommitted? – el_pup_le Jul 13 '17 at 10:38
  • If you want to revert to a point in history, just do a `git reset --hard `. – pishpish Jul 13 '17 at 10:40
  • what if something is changed in my old remote repo, i want to make sure the local repo commits, file modifications etc are tracked to whatever was changed remotely – el_pup_le Jul 13 '17 at 10:43
  • i guess i have to reset then pull? – el_pup_le Jul 13 '17 at 10:46
0

If you want to remove the old repository, you can run git remote remove origin if origin is the name of the old repository. If you want to keep you old repository as a mirror of the new one, you can push the commit on origin: git push origin master.

Hope this helps.

YoannFleuryDev
  • 914
  • 1
  • 12
  • 22
0

Very simple steps:-

Open a command prompt or terminal and type

git config -e

You will see this kind of content

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = <new_repo>
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        email = <local_user>
        name = Atul Agrawal

~                                                                                                                     
~                          

change the origin url to old url and save this file.You will have your old repository configured.

Atul Agrawal
  • 1,474
  • 5
  • 22
  • 41