# Create a new local repositorygit init [name]# Clone a repositorygit clone [url]# Clone a repository into a specified directorygit clone [url] [directory]
Config
# Set the name attached to your commitsgit config --global user.name "[name]"# Set the email attached to your commitsgit config --global user.email "[email]"# Enable some colorization of Git outputgit config --global color.ui auto# Edit the global configuration filegit config --global --edit
Observe your Repository
# Show the commit historygit log# Show the commits that changed filegit log --follow [file]# Show commits on branchA that not on Bgit log branchB..branchA# Show any object in Gitgit show [SHA]
Stage and snapshot
# Show modified files in working directorygit status# Add a file as it looks now to your stagegit add [file]# Unstage a file in working directorygit reset [file]# Diff of what is changed but not stagedgit diff# Commit your staged contentgit commit -m [descriptive message]
Branch and merge
# List your branchesgit branch# Switch to another branchgit checkout my_branch# Create and switch to a new branchgit checkout -b new_branch# Delete the branchgit branch -d my_branch# Merge the branch into the currentgit merge [branch]
Remote
# Add a git URLgit remote add [alias] [url]# Fetch down all the branches from remotegit fetch [alias]# Merge a remote branch to current branchgit merge [alias]/[branch]# Transmit local branch to the remote repogit push [alias] [branch]# Fetch and merge from remote branchget pull
Temporary commits
# Save modified and staged changesgit stash# List stack changesgit stash list# Write working from top of stashgit stash pop# Discard the stashgit stash drop
Tracking and Rewrite history
# Delete the file and stage the removalgit rm [file]# Change a file and stage changesgit mv [old-path] [new-path]# Apply commits of current branchgit rebase [branch]# Rewrite working tree from commitgit reset --hard [commit]
.gitignore
logs/*.notespattern*/# Ignore node_modules foldernode_modules/# Ignore Mac system files.DS_Store# "!" means don't ignore!logs/.gitkeep
Config
.gitconfig
[core] autocrlf = false editor = vim[user] name = email =[alias] st = status br = branch co = checkout ci = commit lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit[init] defaultBranch = main