Home Basic Git Commands
Post
Cancel

Basic Git Commands

Git Init

  • To setup git tracking in a project use this command and you are good to go.
1
git init
  • Git now knows that it should watch the folder you initiated it on. Git creates a hidden folder to keep track of changes.

Staging / Adding files to Git repo

  • Staged files are files that are ready to be committed to the repository you are working on.
  • When you first add files to an empty repository, they are all untracked. To get Git to track them, you need to stage them, or add them to the staging environment.
1
git add <filename with extension>

Staging all files in folder

  • Any of this commands can be used to stage all the modified files in the repository.
1
git add --all
1
git add --A
1
git add .

Git Commit

  • Adding commits keep track of our progress and changes as we work. Git considers each commit change point or “save point”.
  • It is a point in the project you can go back to if you find a bug, or want to make a change.
  • When we commit, we should always include a message. It helps other contributers and ourself to know what changes we made in past.
1
git commit -m "<Enter your message here>"

Git Commit without Stage

  • Sometimes, when you make small changes, using the staging environment seems like a waste of time. It is possible to commit changes directly, skipping the staging environment.
1
git commit -a -m "<Enter your message here>"

Git Status

  • To know the status of the current repository and check for the modified files, you can use this command.
1
git status

More compact way

  • To get the status instantly in more compact way, use this command.
1
git status --short

Git Log

  • To check the history of the past commits and changes you can use this commands.
  • Log is used to view the history of commits for a repo.
1
git log

Use q to exit the log viewing mode. You can use DOWN ARROW to view more past logs.

Git Help

  • If you are having trouble remembering commands or options for commands, you can use Git help.

  • See all the available options for the specific command:

1
git <command> -help
  • See all possible commands:
1
git help -all

If you find yourself stuck in the list view, SHIFT + G to jump the end of the list, then q to exit the view.

This post is licensed under CC BY 4.0 by the author.

Configuring Git for the first time

Git Branch & Merge PR's