Pushing to Repositories With Different Content

Learn to push to repositories with different content.

Same branch name but different content?

You might be asking yourself at this point: what happens if both repositories have a branch with the same name but different content?

Let’s see! Type this out.

1	mkdir git_origin
2	cd git_origin
3	git init
4	echo 'first commit' > file1
5	git add file1
6	git commit -am file1
7	cd ..
8	git clone git_origin git_clone
9	cd git_clone
10	git checkout -b abranch
11	echo 'cloned abranch commit' >> file1
12	git commit -am 'cloned abranch commit'
13	cd ../git_origin
14	git checkout -b abranch
15	echo 'origin abranch commit' >> file1
16	git commit -am 'origin abranch commit'
17	cd ../git_clone
18	git push origin abranch:abranch

Get hands-on with 1200+ tech skills courses.