GIT Bash frequently used commands- Cheat sheet

GIT cheat sheet

Below are some of the common git bash commands, the most frequently used ones are in italic fonts

Scratch- create a new local repository – $ git init {project_name}

Download from existing repo – $ git clone my_appliction_url

List new or modified files not committed – $ git status

show the changes to files not staged/committed – $ git diff

Show all the staged and unstaged file changes – $ git diff HEAD

Show the changes between two commit ids – $ git commit1 commit2

List the change dates and authors for a file – $ git blame {file}

Show the file changes for a commit id and file – $ sit show [commitId]:[file]

Show full change history – $ git log

Show the change history for file including diffs – $ git log -p [file]

List all local branches – $ git branch

list all branches,local and remote – $ git branch -av

switch from one branch to another/update working directory – $ git checkout new_branch

Delete branch – $ git branch -d branch_name

Merge branch_1 into branch_2 – $ git checkout branch_2

$ git merge branch_1

Tag the current commit – $ git tag my_tag

Stages the files ready for commit – $ git add {file}

Stages all the changed files for commit – $ git add .

Commit the staged files – $ git commit -m “commit message”

unstages files, keeping the file changes – $ git reset {file}

revert to the last commit – $ git reset –hard

get the latest changes from origin (without merging) – $ git fetch

fetch the latest changes from origin and merge – $ git pull

Fetch the latest changes from origin and rebase – $ git pull –rebase

push local changes to the origin – $ git push

 

 

 

144 total views, 6 views today

Be the first to comment

Leave a Reply

Your email address will not be published.


*