git log --graph --decorate --simplify-by-decoration --color --oneline --date=local
Stash changes: The stash allows you to temporarily store changes without committing them.
- git stash
You can also add a message to the stash.
- git stash save "<message>"
List stashes
- git stash list
Applying the stash will NOT remove it from the stash list. If you do not specify the <stash id>, the latest stash will be applied (Valid for all similar stash commands)
- git stash apply <stash id>
You can also use the format stash@{<index>} to apply a stash (Valid for all similar stash commands)
- git stash apply stash@{0}
Remove a stash
- git stash drop <stash id>
Remove all stashes
- git stash clear
Apply and remove a stash
- git stash pop <stash id>
Display the changes in a stash
- git stash show <stash id>
git rm -r -f app/unused.txt
git rebase -i HEAD~N -x "git commit --amend --author 'Author Name <author.name@mail.example>' --no-edit"
// "HEAD~N" - "N" is the lasts commits
git reset --hard HEAD~1
//push changed to remote with -f flag
git update-index --assume-unchanged wp-content/themes/workhumanlive-atlanta/assets/images/site.webmanifest
git branch --merged develop | grep -v '^[ *]*develop$' | xargs git branch -d
Delete the local branches for which the remote tracking branches have been pruned
git checkout develop
git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -d
#resolve conflicts automatically
git rebase --continue
#explaining details of git object
git am --show-current-patch
#pseudo-ref that points to the conflicting commit,
git show REBASE_HEAD
#to view the commit, or see commit SHA
git rev-parse REBASE_HEAD
#examine the overall diff
git diff REBASE_HEAD...origin/master $FILEPATH
#list the commits from the target branch that updated $FILEPATH
git log REBASE_HEAD..origin/master $FILEPATH
#review how each modified $FILEPATH
git show $COMMIT_SHA -- $FILEPATH
#to accept the changes from the target branch,
git checkout --ours -- $FILEPATH
#to accept the changes made on your working branch
git checkout --theirs -- $FILEPATH
#Git will record how you resolve conflicts and, if it sees the same conflict during a future rebase (eg if you --abort then retry), it will automatically resolve the conflict for you.
git config --global rerere.enabled 1
#abort rebase
git rebase --abort
assign entire git history from one branch to another branch
git remote add workhuman https://github.com/workhumanweb/workhumanlive.com
git pull workhuman master
git rebase ...
fix conflicts
git rebase --continue
git pull --allow-unrelated-histories origin master
// delete branch locally
git branch -d localBranchName
// delete branch remotely
git push origin --delete remoteBranchName
Renaming branch locally and pushing as new branch
Rename a branch while pointed to any branch, do:
git branch -m <oldname> <newname>
If you want to rename the current branch, you can do:
git branch -m <newname>
If you want to push the local branch and reset the upstream branch:
git push origin -u <newname>
And finally if you want to Delete the remote branch:
git push origin --delete <oldname>
A way to remember this is -m is for "move" (or mv), which is how you rename files. Adding an alias could also help. To do so, run the following:
git config --global alias.rename 'branch -m'
If you are on Windows or another case-insensitive filesystem, and there are only capitalization changes in the name, you need to use -M, otherwise, git will throw branch already exists error:
git branch -M <newname>
multiple git accounts
Case 1: Multiple accounts on Github
Create SSH keys with different names
$ ssh-keygen -t rsa -C "info@webai.lt"
When you see this message
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user_name/.ssh/id_rsa):
Enter unique name, for example:
id_rsa_home
After all steps you can check that all keys were created.
$ ls ~/.ssh
You should see a similar files list: id_rsa_home id_rsa_company id_rsa_home.pub id_rsa_company.pub
Now you need a config file for organise these keys.
$ cd ~/.ssh/
$ touch config
$ nano config
Add into config file:
# Home account
Host home.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_home
# Company account
Host company.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
Next you'll delete cached keys
$ ssh-add -D
If you see a message
Could not open a connection to your authentication agent.
Then enter: eval `ssh-agent -s`
and try again previous command.
Next, you can check that your keys were added:
$ ssh-add -l
2048 d4:e0:39:e1:bf:6f:e3:26:14:6b:26:73:4e:b4:53:83 /home/user/.ssh/id_rsa_home (RSA)
2048 7a:32:06:3f:3d:6c:f4:a1:d4:65:13:64:a4:ed:1d:63 /home/mateusz/.ssh/id_rsa_company (RSA)
If you haven't any entries then you should add your keys
ssh-add ~/.ssh/id_rsa_company
ssh-add ~/.ssh/id_rsa_home
git commit --amend -m "New commit message."
1. modify .gitignore
2. reset cache - git rm -rf --cached .
3. git add .
4. git status
git checkout remote_branch_name
git rm -r --cached _/
git add -u
git cm "remove the folder"
git reset HEAD^ (reworking last commit; changes will stay)
git reset --hard HEAD^ (removing the last commit; changes will be gone)
git reset HEAD~2 (reworking last two commits)
git commit --amend (changing your last commit)
e.g. git commit -m 'initial commit'
git add forgotten_file
git commit --amend
//create branch
git branch <TASK-XX>
//checkout to a branch
git checkout <TASK-XX>
// delete branch locally
git branch -d localBranchName
// delete branch remotely
git push origin --delete remoteBranchName