Category Archives: Git

Basic Git Commands

  • git init : Initialize a Git repository.
  • git status : Check the status of files and folders.
  • git add . : Tell Git to start tracking your files and folders.
  • git add app/ : Track a single folder.
  • git add config/routes.rb : Track a single file.
  • git commit -m “Initial commit” : Save the changes you made, with a message describing the changes.

  • git checkout HEAD filename: Discards changes in the working directory.

  • git reset HEAD filename: Unstages file changes in the staging area.
  • git reset commit_SHA: Can be used to reset to a previous commit in your commit history.

Git branching allows users to experiment with different versions of a project by checking out separate branches to work on. The following commands are useful in the Git branch workflow:

  • git branch: Lists all a Git project’s branches.
  • git branch branch_name: Creates a new branch.
  • git checkout branch_name: Used to switch from one branch to another.
  • git merge branch_name: Used to join file changes from one branch to another.
  • git branch -d branch_name: Deletes the branch specified.

Git Collaborative Workflow are steps that enable smooth project development when multiple collaborators are working on the same Git project:

  • git clone: Creates a local copy of a remote.
  • git remote -v: Lists a Git project’s remotes.
  • git fetch: Fetches work from the remote into the local copy.
  • git merge origin/master: Merges origin/master into your local branch.
  • git push origin : Pushes a local branch to the origin remote.