-
git commit -am "Add comment here"
add and commit all changed files in one code by using-amflag -
git config --global alias.ac "commit -am"
create new custom commands calledacthat adds all changed files and commits (commit -am) -
git commit --amend -m "New message"
update comments of the last commit using--amend -mflag -
git add .
git commit --amend --no-edit
update the last commit with new files using--amendflag, while keeping the old comment using--no-editflag
NOTE: this only works if commmit has not been pushed to remote repo -
git revert {commit hash}
go back to the previous state without removing the last commit -
git stash
git stash pop
remove changes without committing to repo (stash) and add them (changes) back when ready to continue working (stash pop)
-
git checkout {branch name}
switch to branch
NOTE: to go to previous branch you have checked out from use-flag instead of branch name -
git branch -M new_name
rename branch withnew_nameusing-Mflag -
git fetch origin
git reset --hard origin/master
git clean -df
when local repo is messed up and want to go back to original state from remote repo:- get latest code from remote repo with
fetch, - overwrite local code with the fetched remote code using
--hardflag withreset - remove untracked files or build artifacts with
clean
- get latest code from remote repo with
-
git rebase master --interactive
pull up a file with a list of commits on this branch -
git branch -d {branch}
delete a branch using-dflag
-
git log --graph --oneline --decorate
desplay log in more concise fashion -
git log --pretty=format:"%h - %an, %ar : %s"
specify your own log output using format specifiers (e.g.%h) Specifier Description of Output%H- Commit hash
%h- Abbreviated commit hash
%T- Tree hash
%t- Abbreviated tree hash
%P- Parent hashes
%p- Abbreviated parent hashes
%an- Author name
%ae- Author email
%ad- Author date (format respects the --date=option)
%ar- Author date, relative
%cn- Committer name
%ce- Committer email
%cd- Committer date
%cr- Committer date, relative
%s- Subject
$ git push origin --delete <branch> # Git version 1.7.0 or newer
$ git push origin :<branch> # Git versions older than 1.7.0
$ git branch --delete <branch>$ git branch -d <branch># Shorter version$ git branch -D <branch># Force delete un-merged branches
$ git branch --delete --remotes <remote>/<branch>
$ git branch -dr <remote>/<branch> # Shorter
$ git fetch <remote> --prune # Delete multiple obsolete tracking branches
$ git fetch <remote> -p # Shorter
-
git count-objects -vH | grep 'size-pack'checks local repository size -
gh repo list {owner} --json name,diskUsage --limit 999 -
gh repo list {owner} --json name,diskUsage --limit 999 | \ jq '.[] | {name: .name, size_MB: (.diskUsage / 1024 | round) }'checks remote (GitHub) repo size in KB