Git: Difference between revisions
m (move contributor's guide link to the top) |
m (→Introduction: fetch+merge -> pull) |
||
Line 28: | Line 28: | ||
<pre> | <pre> | ||
git remote add upstream https://github.com/dolphin-emu/dolphin.git # add a separate remote for the main repository | git remote add upstream https://github.com/dolphin-emu/dolphin.git # add a separate remote for the main repository | ||
git remote -v | git remote -v # show remotes, you have two now (origin and upstream) | ||
git checkout master # make sure you are on the master branch | |||
git checkout master | git pull --ff-only upstream # pull in new commits from upstream | ||
git | |||
</pre> | </pre> | ||
Latest revision as of 18:43, 12 April 2014
Introduction
If you have never used Git before, here is a quick intro to get you started. For Dolphin-specific workflows, read the Contributor's Guide.
First, set up Git:
sudo apt-get install git # install Git (assuming you are using some Debian-based Linux like Ubuntu) git config --global user.name "John Doe" # commits will be attributed to this identity git config --global user.email johndoe@example.com
Now go to https://github.com/dolphin-emu/dolphin and fork the repository.
git clone git@github.com:YourUserName/dolphin.git # download your fork locally cd dolphin # change into the newly cloned repository (the complete history is inside .git/) git checkout -b cool_new_feature # create a branch for what you are working on $EDITOR some/file.cpp # serious hacking git status # show changed, new or deleted files git add some/file.cpp # mark changes to be committed (adds them to the "staging area") git status # show what is staged git commit # editor pops up, edit the commit message, save, close git push origin cool_new_feature # publish the branch at GitHub
Now you can create a pull request on GitHub.
Your pull requests are tied to your branches. GitHub automatically adds new commits to existing pull requests. To work on something new, always create and checkout a new branch. Otherwise you might accidentally push unrelated commits into one of your previous pull requests. Try to base each pull request on upstream/master so they can be merged independently.
To keep up-to-date:
git remote add upstream https://github.com/dolphin-emu/dolphin.git # add a separate remote for the main repository git remote -v # show remotes, you have two now (origin and upstream) git checkout master # make sure you are on the master branch git pull --ff-only upstream # pull in new commits from upstream
If you messed up and want to delete all uncommitted changes (be careful!):
git reset --hard
Useful Git Commands
git show # show last commit git diff # diff current working directory to last commit git log --graph # draw ASCII graph of Git history git commit --amend # add changes in staging area to previous commit git rebase -i upstream/master # rebase current branch onto master and interactively select order of commits, meld commits together, or delete some git reflog # show list of recent hashes (even commits outside of the history, would be garbage-collected when left alone)
It may be useful to know that Git branches are actually just labelled pointers into the commit graph.