How can i set one gameobject as another in code?

How can i do this:

GameObject a;
GameObject b;

a = b;

I can try to, but it says that it is read-only, how can i get around this?

There is nothing wrong with you are trying to do. The following compiles:

using UnityEngine;
using System.Collections;

public class Bug25a : MonoBehaviour
{
	public GameObject a;
	public GameObject b;

	
	void Start () {
		GameObject c ;
		GameObject d = GameObject.Find("Player");

		a = b;
		c = d;
	}
}

To help you solve your problem, we would need to see the exact code that is generating the error you describe.