el_pup_le
el_pup_le

Reputation: 12189

Switching tracking between git repositories

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.

Upvotes: 0

Views: 71

Answers (3)

pishpish
pishpish

Reputation: 2614

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

Upvotes: 1

Atul Agrawal
Atul Agrawal

Reputation: 1520

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.

Upvotes: 0

YoannFleuryDev
YoannFleuryDev

Reputation: 941

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.

Upvotes: 0

Related Questions