Skip to content

Instantly share code, notes, and snippets.

@mkeneqa
Last active November 8, 2019 09:05
Show Gist options
  • Save mkeneqa/7acb9f1a4b2bc8a7e958 to your computer and use it in GitHub Desktop.
Save mkeneqa/7acb9f1a4b2bc8a7e958 to your computer and use it in GitHub Desktop.
Git Useful Commands
## force checkout a new branch and discard non-committed changes on current branch
$ git checkout -f
## discard any changes on current branch and reset it to the latest version/head on local repo
$ git reset --hard
## merge current branch with another / master branch
$ git merge origin/master [-- no-commit]
## remove all untracked files in current branch
$ git clean -fd
git checkout source_branch <paths>...
$ git branch
* master
twitter_integration
$ git checkout twitter_integration app/models/avatar.rb db/migrate/20090223104419_create_avatars.rb test/unit/models/avatar_test.rb test/functional/models/avatar_test.rb
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: app/models/avatar.rb
# new file: db/migrate/20090223104419_create_avatars.rb
# new file: test/functional/models/avatar_test.rb
# new file: test/unit/models/avatar_test.rb
#
$ git commit -m "'Merge' avatar code from 'twitter_integration' branch"
[master]: created 4d3e37b: "'Merge' avatar code from 'twitter_integration' branch"
4 files changed, 72 insertions(+), 0 deletions(-)
create mode 100644 app/models/avatar.rb
create mode 100644 db/migrate/20090223104419_create_avatars.rb
create mode 100644 test/functional/models/avatar_test.rb
create mode 100644 test/unit/models/avatar_test.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment