Skip to content

Instantly share code, notes, and snippets.

@iruwl
Last active June 18, 2021 11:53
Show Gist options
  • Save iruwl/bad4c2128660dbd93e2d2c51b5ebf862 to your computer and use it in GitHub Desktop.
Save iruwl/bad4c2128660dbd93e2d2c51b5ebf862 to your computer and use it in GitHub Desktop.
Perintah Dasar GIT #git #tutorial

Here is a list of commonly used git commands

Source : http://shabeebk.com

  • Initiate a directory as git

    git init --bare

  • Git clone

    git clone url-to-git

    example URL :user@domain.com:/home-path/username/directory/

  • Git status

    it will show the files status - modified, tracking , untracked

    git status

  • Git Add for tracking

    git add filename

    or

    git add .

    dot is using to add all files

  • Git commit

    git commit -m "commit message"

    If the file is under git track we can combine both comments in one line like

    git commit -am "your-message"

    or

    git commit -a -m "your-message"

    -a to add

    -m to commit message

  • Push your changes to server

    git push

    or

    git push branch

  • Creating branch in git

    git branch branch-name

  • Switch to branch

    git checkout branch-name

  • Create a new branch and switch to new branch

    git checkout -b branch name

  • List all the branches

    git branch -a

  • Merge Branch

    Consider we have master branch A and another branch B, To merge branch B changes to branch A,

     git merge branch B```
    
     if any conflict happened, it will show conflict, we have to do modification and commit again.
    
    
  • Delete a branch

    ```git branch -d ``

    this will delete if all the changes are merged, if you want to use force delete , even not merged,

    git branch -D <branch name>

  • Upload branch into server at setting head for push

    git push --set-upstream origin <branch name>

  • Stash all local changes

    git stash

  • Take back stashed changes - This will take aback all the changes you stashed

    git stash pop

  • Discard changes on one file

    git checkout filename

  • Remove local commit and reset to server head - it will delete all the local changes

    git reset --hard origin/branch name

  • List all the branches push/pull remote origin.

    This will show all the remote and local branches and where it is pointing into

    git remote show origin

  • Fetch and push origin list

    git remote -v

  • View uncommitted changes made

    git diff

  • To see all the logs

    git log

  • To see log with difference

    git log -p

  • Git log for a single file

    git log -p file/path

    -p will give changes also

  • Other options with git log

    git log --stat //this will show only number of files changed and number of changes

    git log --pretty=oneline //show all the changes in one line with head and comment

    git log --pretty=format:"%h - %an, %ar : %s" //show with name time and commit message

    git log --author=username //show only one user commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment