Skip to content

mihairusu88/git_commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 

Repository files navigation

Initialize


Command Description
git init Initialize a local Git repository

Create


Command Description
git clone https://github.com/[username]/[repository].git
git clone ssh://[email protected]/[username]/[repository].git
Create a local copy of a remote repository
E.g: git clone https://github.com/johndoe/my-repository.git
E.g: git clone ssh://[email protected]/johndoe/my-repository.git

Status


Command Description
git status Check status

Adding files


Command Description
git add [filename] Add a filename to the staging area
git add -A
git add .
Add all new and changed files to the staging area

Commit changes


Command Description
git commit -m "[message]" Commit changes
E.g: git commit -m "Added some new code in index.html"

Branching & Merging


Command Description
git branch List branches (the asterisk denotes the current branch)
git branch -a List all branches (local and remote)
git branch [branch_name] Create a new branch
E.g: git branch development
git branch -d [branch_name] Delete a branch
E.g: git branch -d development
git checkout -b [branch_name] Create a new branch and switch to it
E.g: git checkout -b development
git checkout [branch_name] Switch to a branch
E.g: git checkout development
git checkout - Switch to the branch last checked out
git checkout -- [filename] Discard changes to a file
E.g: git checkout -- index.html
git merge [branch_name] Merge a branch into the active branch
E.g: git merge development
git merge [source_branch] [target_branch] Merge a branch into a target branch
E.g: git merge development master
git stash Stash changes in a dirty working directory
git stash clear Remove all stashed entries

Updating Projects


Command Description
git push origin [branch_name] Push a branch to your remote repository
E.g: git push origin development
git push -u origin [branch_name] Push changes to remote repository (and remember the branch)
E.g: git push -u origin development
git push Push changes to remote repository (remembered branch)
git push origin --delete [branch name] Delete a remote branch
E.g: git push origin --delete development
git reset --hard HEAD Scrap uncommitted state and return the working tree to the last committed state
git reset --hard HEAD~1
and then
git push origin master --force
Delete the latest commit, and return to the one previous (one before HEAD)
git rm --cached [file/folder] Stop a file being tracked (but do not delete it from the working directory, add to .gitignore etc after this)

Inspection & Comparison


Command Description
git log View changes
git log --summary View changes (detailed)
git diff [source_branch] [target_branch] Preview changes before merging
E.g: git diff development master