Skip to content

Instantly share code, notes, and snippets.

@raghav4
Last active March 11, 2020 13:39
Show Gist options
  • Select an option

  • Save raghav4/f977b9f111c456848e71bf7954c3d3d0 to your computer and use it in GitHub Desktop.

Select an option

Save raghav4/f977b9f111c456848e71bf7954c3d3d0 to your computer and use it in GitHub Desktop.
git commands

Commands

  • git init - Initialize a git repository

  • git status - Gives the status of the git repository

  • git add <filename> - Add a file to the index

  • git add . - Add every file to the index

  • git pull - Pull the files from the remote repository

  • git push - Push changes from the local to the remote repository

  • git branch - List all the branch in the repository

  • git checkout -b newBranchName - Here -b flag creates a new branch and checkout to that branch, can also be written as gco -b newBranchName.

  • git branch -d branchName - Deletes a branch

  • git log - Lists all the logs of the repository

    • All the logs are in reversed order.
  • git log --oneline - Log in oneline

  • git log --oneline --color --graph --decorate - Shows the git logs in a beautiful way with graph

  • git stash - Reverts the branch to the remote branch.

  • git restore --staged <file> - unstage the file

  • git reset --hard <commit id> - reset the git directory to a git commit id, here --hard make changes locally, --soft doesn't change the changes in your local directory.

Tips

  • Adding date in the commit

    • git commit -m "date" filename
    • git commit -m "`date +'%Y-%m-%d'`" # 2020-01-25
  • Adding emoji's in the commit message - Use these emojis

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