9/27/2019 - 9:23 AM

git Oneliners

[git Oneliners] git one-liners #git #oneliner

# rename repository
# change name on remote repo, copy ssh url from the clone button on main page
mv <old folder> <new folder>
git remote set-url origin<new repo name>

# compare local copy of file to remote
git fetch origin
git diff origin/master -- <path to file>

# list all branches
git branch -a

# create a new branch
git checkout -b <branch>

# count total lines of code in git repo
git ls-files | xargs wc -l #or
git ls-files | xargs cloc

# only pull single file
git fetch origin
git checkout FETCH_HEAD -- <path to file>

# compare file between branches
git diff master..other_branch -- <path to file (or glob)>

# overwrite existing branch with another
git checkout <branch to keep>
git merge -s ours <branch to overwrite>
git checkout <branch to overwrite>
git merge <branch to keep>

# remove file from repo but don't delete local file
git rm --cached <file>

# view untracked files
git ls-files . --ignored --exclude-standard --others