Git: how to set up two remotes and check out a previous commit

This is a post for myself, recording my experience with learning how to use git with

(1) multiple remote repositories and

(2) see the content of a previous commit.

(1) Git add a new remote, name it as “upstream”, so now I have two remotes “origin” and “upstream”.

when I need to get the updates from upstream, I can do a

git fetch upstream

git rebase upstream master

to put the changes back to the master branch. When I do a

git pull

it will get the code from origin and merge with the current master branch.

(2) When I need to see the content of a previous commit, or revert back to a previous commit, I can do

git checkout xxxxxxxx -b temp

so that i see the previous checked in file in a different branch. Branch is a lot more lightweight in git than in svn.

I can see the file, and whenever I need to get back to the current latest commit, I do a git rebase master.

NOTE: when I do

git checkout xxxx

without specifying a  branch, I will be detached from current head and NO LONGER in master branch. As a result, to change anything, we need to checkout the latest branch to reattach to the head of master.

Advertisements
This entry was posted in git. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s