~By AbhinayGit & Git-hub

title image

Git:

  • used for version control.
  • Installed locally on computer.
  • Tracks changes made to file.

Git-hub:

  • Used for hosting git repositories.
  • Cloud based.
  • Provides a web interface to view file changes.

Git commands

Clone: Bring a repo hosted somewhere like Git hub into a folder on your local machine.

Add: Track your files and changes in Git.

Commit: Save your files in Git.

Push: Upload your commits to git repo, like Git-hub.

Pull: Download changes from a remote repo to your local repo.

How to commit files (first use cd and navigate to that particular folder)

  1. git init
  2. git status
  3. git add .
  4. git status
  5. git rm - -cached <file> → to remove any file.
  6. git commit -m “any message”
  7. git remote -v →check whether repo is already created to push our changes from local
  8. git remote add origin (repo link).git
  9. git status
  10. git push / git push origin master → if you want to push in master
  11. git push -u origin main → if you want to push in main

How to clone a website

  • got to the repo which you want to clone → click on “<> code “ button and in HTTPS copy the link
  • use cd and move to the place where u want to clone
  • git clone (paste the link here)

How we can create a sub branch/ new branch..

  • git branch → will respond you which branch
  • git checkout -b (name it based on what u are doing ex- feature_new) → creates a branch
  • git checkout master (will shift you to master)
  • git checkout main (will shift you to main)
  • git branch → (will show u in which u are right now)
  • git checkout (branch name ex- feature_new) → enters into given branch
  • if u want to edit that then either edit through cmd using vi or directly through code but need to commit.
  • move to main → git checkout main
  • git diff branch-name (ex- feature_new) → will show u the changes you made
  • git status
  • git push -u origin branch -name (ex- feature_new)

Note: Here instead of "feature_new" give your own branch name

Git commands to resolve conflicts

  • git log —merge: produce the list of commits that are causing the conflict.
  • git diff : Identify the difference between the states repositories or files.
  • git checkout : Used to undo the changes made to the file, or for changing branches.
  • git reset —mixed: Used to undo changes to the working directory and staging data.
  • git merge —abort : Helps in exiting the merge process and returning back to the state before the merging began.
  • git reset : Used at the time of merge conflict to reset the conflicted files to their original state.
  • git branch -d branch name : to delete a branch

Conclusion:

This personalized guide covers essential Git and GitHub commands for version control, including cloning repositories, committing changes, creating branches, and resolving conflicts. By following these instructions, you can efficiently manage and track your project changes locally and on GitHub. This cheat sheet was tailored specifically by me, providing a handy reference for both basic and advanced Git operations. Whether you’re a beginner or an experienced developer, this guide will help streamline your workflow and enhance your version control proficiency.