Skip to content

amrk000/git_commands-cheat_sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 

Repository files navigation

Command Description

Main Operations

git init

initialize current project folder for version control (creates .git files)

git status

show status of current branch: the changes that need to be staged (tracked) or committed

git add .

add all changed files to stage/index

git add FILE

add file to stage/index

git rm FILE --cached

remove files from stage/index

git rm FILE

delete file

git commit -m "MESSAGE"

commit changes

git commit -m.

commit changes without message

git commit --amend

Edit/overwrite last commit

git revert COMMIT_ID

undo by creating a new commit with reverted changes from previous commit

git reset COMMIT_ID

[Danger] commits (removes all commits until selected one & make changes untracked)

Flags: --hard (force remove changes) , --soft (put changes in stage)

git checkout FILE

[Danger] restore file from last commit and remove uncommited changes

git mv old_FILE new_FILE

rename file

git log

show history of commits

git log -p

show history of commits & changes

git log -p --author=userName

show history of commits & changes by specific user

git log -p --since=2.days

show history of commits & changes in time duration (minutes, hours, weeks, etc...)

git blame FILE

show when each line was last modified in file & who did it

Branches Operations

git branch

list all local branches

git branch -a

show all including remote branches

git branch BRANCH_NAME

create new branch

git branch -d BRANCH_NAME

delete branch

git checkout BRANCH_NAME

move to branch

git merge BRANCH_NAME

merge a branch to current branch (in new commit)

git rebase BRANCH_NAME

merge a branch to current branch (editing commits chain of current branch)

Remote Operations

git clone REPO_URL

get copy of remote repo

git remote add REPO_NAME REPO_URL

add remote repo

git pull REMOTE_REPO_NAME REMOTE_BRANCH_NAME

get remote repo latest files

git fetch REMOTE_REPO_NAME REMOTE_BRANCH_NAME

get remote repo changes history

git push REMOTE_REPO_NAME REMOTE_BRANCH_NAME

update remote repo

git remote

show all remote repos

git push REMOTE_REPO_NAME --delete REMOTE_BRANCH_NAME

delete remote branch

creating .gitignore

make a file .gitignore without extensions and add directories & files

Example:

# comment: Project exclude paths
/folder/
file.txt

updating .gitignore (untrack files)

add file path in .gitignore file then Open git bash and Run:

git rm -r --cached .

Auth with Token instead of password (passwords removed)

github website > Settings > Developer Settings > Generate New Token

copy token

method 1:

add remote repo url and login with user name and paste token in password

method 2:

replace the link below with your data and use it as remote repo url

https://{PROJECTNAME}:{TOKEN}@github.com/{USER_OR_ORG}/{REPOSITORYNAME}.git


⬇ Save Git Commands (Cheat Sheet): Download Image Download PDF

About

Git Commands (Cheat Sheet)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published