Auralinna.blog - Tero Auralinna's web development blogAuralinna.blogTero Auralinna's blog about intriguing world of web development. Tweaking pixels since the '90s.

Git commands reference

Published: 12/4/2021. Updated: 12/30/2021

This post is mainly a personal reference for Git CLI commands, which I use more or less frequently. This will be living documentation, that will be updated from time to time.

I mainly work with the command line. For merge conflicts, diffs, and patch selections I prefer VS Code's UI.

Clone and pull

Clone a project into a current directory

git clone <project url> .

Change the remote origin

git remote set-url <remote_name> <remote_url>
git remote -v

Or edit via .git/config file.

Pull and rebase after someone else force pushed into a branch

git pull origin <branch> --rebase

Set the committer identity

Globally

git config --global user.name "Someone"
git config --global user.email "someone@somewhere.com"

Locally for a single repository

git config user.name "Someone"
git config user.email "someone@somewhere.com"

Branches

Create a new branch and checkout the branch with a single command

git checkout -b <branch>

Deleting local and remote branches

Local

git branch -d <branch> # To see if there are unmerged changes
git branch -D <branch>

Remote

git push origin --delete <branch>

Rename a local branch

git checkout <branch>
git branch -m <new-branch-name>

Rebase, amend, and cherry-picking

Select how many commits you want to rebase

git rebase -i HEAD~6

Force push rebased changes

git push origin <branch> --force

Stop for amending

Use the rebase command and mark wanted commits by "e", which means that when doing the rebase it will stop for amending.

git rebase -i HEAD~6
git commit --amend
git rebase --continue

Change the date of the last commit

git commit --amend --date="now"

Change the committer of the last commit

git commit --amend --author="Someone <someone@somewhere.com>"

Cherry-pick a commit

git cherry-pick <commit-hash>

Stash changes and clean up the working directory

Stash changes (also untracked)

git stash -u

List all stashes

git stash list

Add a stash back to working directory

git stash apply stash@{1}

Reflog

Show Git reflog with dates

git reflog --date=iso

Be the first commenter?

Latest CodePens

I am an experienced web developer with an eye for solid UI/UX design. I have specialized in front-end development, responsive web design, design systems, modern web frameworks, and content management systems. I also have experience in mobile apps development and back-end coding with PHP, Node.js, and Java. So I have a full stackish background, but I'm enjoying most building robust and beautiful front-ends with performance, accessibility, and testability in mind.

© Tero Auralinna

Auralinna.fiSunset with Bubbles: Travel and Photography Blog

The icon "ellipsis" is provided by loading.io