# Git

It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows. - Home

Git branches are pointer to a commit - Git Branches Have No Rules - Git Branches: Intuition and Reality

see also

caption

Config

git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"

git config --list

Diff tool

Meld understands git and provides navigating around the recent changes.

meld .

mtime

see Why isn’t Git preserving modification time on files? - short to stay compatible with make

If you wan’t original times (rather than checkout times) use this tool

sudo apt install git-restore-mtime
cd [repo]
git restore-mtime

Basic Cmd

Undo last commit, keeping change

$ git reset --soft HEAD~    # Undo the last commit but leave the changes in the staging area

$ git reset HEAD^

see also: How do I undo the most recent local commits in Git?

Abort merge

git reset --hard HEAD
git clean -fd  

Checkout branch

# without using origin/xx
git checkout <branch from above>    

Add origin as new github repo

git remote add origin git@github.com:yduf/<repo>.git

Remove origin

git remote rm origin

change a Git repo’s origin

git remote rename origin upstream
git remote add origin git@github.com:user/fork.git
  
# then point the master branch to your new remote (as it has been automatically changed to upstream)
git config branch.master.remote origin
Written on October 30, 2018, Last update on October 7, 2024
git diff vcs