Config changes
🚀 A better git log 👈
% git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Fast-forward only for pulls
This will help avoid merge conflicts on pulls. Why?
In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.
% git config --global pull.ff only
Add tracked files only
% git add -u
% git commit -a -m '<insert your comments here>'
% git push
% git pull origin master
Get files from repository
Go to the root directory you want the rep directory
% git clone https://code.server.com/pwong/<repo_name>.git
% cd <rep_name>
% git pull
Add files to git hub
% git add <filenames>
% git commit -m 'add your comments here'
% get push
Get updated files from hub
% git pull
Rebase with squashing
% git rebase -i
Show names only on commit
% git diff-tree --no-commit-id --name-only -r 7c255b07b
Show what a commit added
Commit hash and add ^!
Example
% git diff 07d167f^!
File names only
% git diff --name-only c022600^!
Diff a branch
% git diff master...<your_branch>
Bundle
Bundle allows you to get git changes from one machine to another.
On the source machine.
% git bundle create file.bundle HEAD
On the destination machine.
% git pull file.bundle HEAD
Error: Fatal: Not possible to fast-forward, aborting
% git pull --rebase
Resolving merge conflicts for the entire file
If you face merge conflicts, but you know that one version of the file is the “right” version, there is a nice shorthand using the flags –ours or –theirs
% git merge feature/some-new-feature
CONFLICT (content): Merge conflict in conflict.txt
Automatic merge failed; fix conflicts and then commit.
% git checkout --theirs conflict.txt
% git add conflict.txt
% git commit
This is effectively the same as going through the conflicting file and slicing and dicing all the <<<<<<<<<<<<
>>>>>>>>>>>>
stuff to pick one side of the merge exclusively but without all the headache and error potential
Note theirs/ours is from the perspective of your current branch (i.e. a conflict resulting from % git merge feature-branch
means % git checkout --theirs <file>
is the same as % git checkout feature-branch --<file>
)
Delete a branch
Local
% git branch -D <local-branch>
Remote
% git push origin --delete <remote-branch-name>