Git Cheat Sheet

A Programming › Git cheat sheet in English by elisarma

Git commands for day to day life

2,531 views 545 downloads 6 Aug 2024 History

Working with Branches

git branch
List branches
git branch [branc­h_name]
Creates new branch
git checkout -b [branc­h_name]
Creates and switch to a new branch
git checkout [branc­h_name]
Switch to branch
git branch -d [branc­h_name]
Deletes branch
git branch -m [old_name] [new_name]
Renames branch

Working with Remote

git remote add [remot­e_name] [repos­ito­ry_url]
Add a remote repo
git pull [remot­e_name] [branc­h_name]
Pull changes from a remote repo
git push [remot­e_name] [branc­h_name]
Send changes to a remote repo

Order of Work

git init
git clone [repos­ito­ry_url]
git checkout -b [branc­h_name]
make modifi­cations
git add [file_­or_­dir­ectory]
git commit -m '­mes­sag­e'
git push [remot­e_name] [branc­h_name]
create pull request on UI
git fetch origin
git pull origin main
git push [remot­e_name] [branc­h_name]

Initia­lizing, Staging and Commiting

git init
Initialize the repo on git
git clone [repos­ito­ry_url]
Clone an existing repo
git add [file_­or_­dir­ectory]
Stage changes for commit
git commit -m '­mes­sag­e'
Commit with short message (-m)
git reset
Retorna para unstage
git reset [commit]
Tira arquivo do stage

Info

git status
Check the status of changes
git log
View commit history
git diff [commit1] [commit2]
Show changes between commits
git diff
Show changes between working directory and last commit

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.