-
Notifications
You must be signed in to change notification settings - Fork 1
Very Common and Very Uncommon Git Workflows
This assumes git and git tools (differ, merger) are configured. If not, see Git - General Prerequisites
git init
git status -u
Without the -u, you won't see files inside of new directories
git difftool -d
This should launch something like WinMerge, or whatever you have configured.
git add -A
git commit -m "Stuff I just did comment"
These two commands are probably used 100 times more than any other command.
git log --oneline --date-order --graph --d -10
I suggest using "alias.logs". See Git - General Prerequisites. then you get just type git logs -10
git difftool -d --cached
It's not that common, but good to remember you can do this.
git commit --amend
This is great if you want to have a workflow that just periodically "saves" to the local commit, without making history.
git reset --soft HEAD^
This moves all the files in the last local commit to the workspace and moves the head to the parent commit. It's as if you didn't do a commit.
Do this if you do a commit, and changed your mind.
Note, if doing this from a DOS Command prompt, use HEAD~1 instead of HEAD^. But PowerShell is okay. This is because the ^ is the DOS escape character so you'd have to do ^^ to mean ^, and that's confusing because the number of ^s you pass to git is significant. So to go up 3 commits from HEAD, you'd have to double-up and do HEAD^^^^^^. It's just easier to use the alternate syntax using tilde and type HEAD~3.
git remote add origin <url-to-remote>
git push -u origin master
https://github.com/<username>/<repository name>.git
git clean -xfd
This is like deleting all temporary files -- it's as if you deleted everything and then did a fresh get.
git checkout master
git merge --squash bugfix
git commit...
This will take all the commits from the bugfix branch, squash them into one commit and then merge it with your master branch.
If you want to keep references to the old commit messages you can write git commit (without -m param) and you will get to modify a drafted commit message containing all commit messages that you squashed
git init --separate-git-dir ./git
git push --all origin -u
I want to switch to master and pull latest but for performance reasons, I don't want the working directory to switch to a stale master only to be immediately replaced with the new stuff on on origin.
git fetch
git checkout -B master origin/master
I'm on master, and I want to squash all of my local commits since origin into a single commit before doing a push.
git rebase -i origin/master
git reflog
or
git fsck --lost-found
git push origin origin/<old_name>:refs/heads/<new_name> :<old_name>
git log -p --grep "nasty bug"
git log -p -S 'Date.new'
git log -S 'populate_database' --all
git push -u origin <branch_to_publish>
git push origin :<branch_to_publish>
or
git push origin --delete <branch_to_publish>
git branch --contains <commit>
or
git reflow show --all | grep <commit>
Untracked
'add' --> Unmodified
'edit' --> Modified
'stage' --> Staged
'commit' --> Unmodified
'remove' --> Untracked