The whole congregation of Israel moved on from the wilderness of Sin and camped at Rephidim, but there was no water to drink. The people quarreled with Moses and demanded water; Moses asked why they quarreled with him and why they tested the Lord. Thirsty, the people grumbled against Moses and asked why he had brought them up out of Egypt to kill them, their children and their livestock with thirst. Moses cried out to the Lord, saying they were almost ready to stone him.
The Lord told him to pass on before the people with some of the elders of Israel and take the staff with which he had struck the Nile. He would stand before him on the rock at Horeb. Moses was to strike the rock and water would come out for the people to drink. Moses did so in the sight of the elders. He called the place Massah and Meribah, because of the quarreling of the Israelites and because they tested the Lord, saying whether the Lord was among them or not.
Then Amalek came and fought against Israel at Rephidim. Moses told Joshua to choose men and go out to fight the next day, while he would stand on top of the hill with the staff of God in his hand. Joshua fought Amalek, and Moses, Aaron and Hur went up to the top. Whenever Moses held up his hand, Israel prevailed, and whenever he lowered it, Amalek prevailed. When Moses' hands grew tired, they took a stone and put it under him and he sat on it, and Aaron and Hur held up his hands, one on each side, until the going down of the sun. Joshua overwhelmed Amalek and his people with the sword.
The Lord told Moses to write this in a book as a reminder and to tell Joshua that he would utterly blot out the memory of Amalek. Moses built an altar and called it The Lord Is My Banner, saying the Lord would be at war with Amalek from generation to generation.