Coffee loses its quality or goes bad by two ways. They are de-gassing and there is growth of undesirable compounds in it. Before roasting, coffee beans have the same level of carbon dioxide as the air around but once it’s roasted the CO2 percentage goes up by at least 2 percent in each bean. The gas leaks from the bean the moment roast ends. The gas released leads to the loss of the coffee’s aromatics. They are also called volatile organic compounds. This is mainly the oxidization of the beans. Coffee turning bad in flavour is basically the result of aging and oxidization.
Thus it can be concluded that oxygen is the real danger for coffee beans. That’s the reason why most bags of coffee nowadays feature a small valve hole. The one way hole degasses the carbon dioxide from escaping so that the bag doesn’t inflate and explode. This hole doesn’t allow oxygen into the bag. Thus the bag is mainly filled with carbon dioxide making its way out of the bag and very little oxygen.
The carbon dioxide in the bag acts like a blanket by covering the coffee beans for oxygen so that even when the bag is reopened to prepare coffee, it doesn’t lose carbon dioxide. So dumping all the beans into a new container is wrong method as the container contains oxygen and one is basically just disposing of the valuable C02 blanket by replacing it with oxygen-containing atmosphere.
The best would be to keep it the same bag and use one of the best coffee makers when you have to drink the coffee. Use the coffee within 2 weeks of it being roasted so that it’s still in its best form when had and hasn’t degraded much. Coffee goes stale in 3 months depending completely on packaging material and atmosphere.