Skip to content
gustaff-weldon edited this page Jun 20, 2011 · 3 revisions

Some useful git commands

Regular development

Clone repository:

git clone [email protected]:gustaff-weldon/puzzle.git

To get recent changes from github (from master branch):

git pull origin master

To check status of workspace (list changes):

git status

To show diff of the changes in workspace:

git diff
git diff path/to/file(s)

To add files to next commit:

git add path/to/file(s)

To commit changes (added before):

git commit -m "commit message"

To commit changes and automatically add modified files (doesn't add new files):

git commit -am "commit message"

To push commits from local repo to github (local master branch to remote master branch):

git push origin master

To publish repo on GitHub Pages (push to remote gh-pages branch):

git push origin master:gh-pages

To push commits from local master to remote master and publish repo on GitHub Pages (gh-pages):

git push origin master master:gh-pages

Troubleshooting

Change commit message of the last commit:

git commit --amend

Revert changes from last commit (doesn't remove the commit, safe when commit already pushed):

git revert HEAD

Remove last commit from history (don't do it if commit was already pushed):

git reset --soft HEAD~1

Where --soft means you want to keep changed files in workspace. Using `--hard' option will drop your changes.

To edit some past commits (change messages, amend, merge to single commit - again, don't do it for pushed changes):

git rebase -i HEAD~5

Where ~5 is the number of commits in the past you want to change.

Clone this wiki locally