You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Set global username & email
$ gitconfig --globaluser.name"John Doe"
$ gitconfig --globaluser.emailjohndoe@example.com# Set global editor
$ gitconfig --globalcore.editorsublime# Set global mergetool
$ gitconfig --globalmerge.toolkdiff3# Check config list
$ gitconfig --list# Check individual config
$ gitconfiguser.name
Feature branch workflow
# Checkout a new branch for the new feature
$ gitcheckout -bfeature_1# Make changes for the feature & commit changes
$ gitcommit -a -m'make changes for [feature_1]'# Checkout a branch to merge the feature branch into it
$ gitcheckoutmaster# Merge the feature branch
$ gitmergefeature_1# Delete the feature branch
$ gitbranch -dfeature_1# EXTRA# In case of switching the workstation push the feature branch to the remote repository.# Use the -u option to setup upstream references required for git pull.
$ gitpush -uoriginfeature_1
Commit a single file with multiple modified files in the working directory.
# Check current status
$ gitstatus# Check what has changed for the single file.
$ gitdiffHEADapp/models/quiz_user.rb# Commit the changes made to the single file.
$ gitcommit -m"Add :entries_for_quizzes to quiz_user"app/models/quiz_user.rb
Remove multiple deleted files.
# Changes not staged for commit:# (use "git add/rm <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## deleted: app/views/admins/offer_codes/_form.html.erb# deleted: app/views/admins/offer_codes/edit.html.erb# deleted: app/views/admins/offer_codes/new.html.erb# deleted: app/views/admins/offer_codes/show.html.erb# deleted: app/views/admins/offers/_form.html.erb
$ gitadd -u
-u, --updateOnlymatch <filepattern> againstalreadytrackedfilesintheindexratherthantheworkingtree.Thatmeansthatitwillneverstagenewfiles,butthatitwillstagemodifiednewcontentsoftrackedfilesandthatitwillremovefilesfromtheindexifthecorrespondingfilesintheworkingtreehavebeenremoved.Ifno <filepattern> isgiven,defaultto".";inotherwords,updatealltrackedfilesinthecurrentdirectoryanditssubdirectories.Note: Thisaddsthemodifiedtrackedfilestothestagingareaaswellsorunthiscommandonlyifyouhadjustremovedthefilesandwanttostagethemimmediately.
# Consider 2 files have changed. a.txt & readme.MD
$ gitaddreadme.MD
$ gitcommit -m"2 Files changed in this commit"# We forgot to "git add a.txt". We use amend to add it to the previous commit.# --no-edit skips opening the editor.
$ gitadda.txt
$ gitcommit --amend --no-edit# Changes to both files will now be in the same commit "2 Files changed in this commit"
Git alias for a command
# Creates alias for "git po" -> "git push origin master"
$ gitconfig --globalalias.po"push origin master"# Check if alias was correctly created.
$ gitconfig --global --getalias.po
Git apply specific version of stash
# View list of stash available. ( stash@{0} is the latest stash )
$ gitstashliststash@{0}: WIPonmaster: 44278f1Shownestedcategoryontheindexpage.stash@{1}: WIPonmaster: 44278f1Shownestedcategoryontheindexpage.# Apply specific stash
$ gitstashapplystash@{1}