Skip to content

Instantly share code, notes, and snippets.

@anupam-io
Last active May 19, 2021 12:54
Show Gist options
  • Save anupam-io/dc8829d8d5c190c8e5f7615f4f7c73d8 to your computer and use it in GitHub Desktop.
Save anupam-io/dc8829d8d5c190c8e5f7615f4f7c73d8 to your computer and use it in GitHub Desktop.
The minimalistic git knowledge that you must know.

Git: The version control system

Initializing a git repo

  • git init: initialize a git repository

Connecting to a Online repository

  • git remote add origin https://github.com/akcgjc007/avl_tree.git: Connect your git to an existring online repository
  • git remote -v: Show connected repositories

Adding files

  • git add .: Add all files present in the current directory.
  • git add <filename>: Add a particular file.

Commiting changes

  • git commit -m "Commit message": Commiting currently staged changes
  • git commit -a -m "Commit message": Staging and commiting alll current changes

Pulling changes

  • git pull: Will pull the changes done by other collaborators

Switching branch

  • git switch <existing-branch>: Will switch to a branch that already exists.
  • git checkout -b <non-existing-branch>: Will create a new branch for you.

Deleting branches

  • git branch -d <branch>: delete the local branch
  • git push -d origin <branch>: delete the online branch

Pushing changes to online repository i.e. Github/Bitbucket

  • git push: Push current commits
  • git -f push: Forced push commits, will remove any conflicting changes

Reverting changes

  • git stash: Will remove all uncommited changes
  • git reset --hard: Go back to the previous commit
  • git reset --hard HEAD~3: go back to three commits before
  • git reset --hard HEAD^^^: go back to three commits before
  • git reset --hard <commit-hash>: go back to this specific commit

Ignoring files

  • Add a .gitignore file into you directory, and name any files and folder that you don't want to commit
  • myFolder/: Will ignore all files in myFolder
  • *.png: Will ignore all png files in the current directory

Removing git

  • git remote remove origin: Remove the online associations from git
  • rm -rf .git: Will remove all associations of git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment