TOP 20 Commands : Git/GitHub Cheat Sheet

 TOP 20 Commands  Git/GitHub Cheat Sheet

Git and GitHub:
Git is the actual version control system. It is an open source DVCS (distributed version control system) that runs in the command line. This basically means it saves the entire history of the project.
GitHub, commonly confused with Git, is actually a repository hosting service. 
Installation of GIT & Creating A/C on GITHUB:
Download GIT for window/Mac(depends upon OS)
Use Git Bash, which is available when you install Git
Once git is installed go ahead and create a free account to GitHub. 


Cheat Sheet


Command-1:  git init

This will create a .git repository in your project. A repository or “repo” is a collection of all the

changes you’ve made to your project over time and will build a history of these changes. This is

the first thing you want to do with a new project.


Command-2:

 git config --global user.name "Your Name"

 git config --global user.email "yourEmail@mail.com"

This sets up your information that is used every time you commit. This only needs to be done

once when you first install Git.


Command-3: git add filename.extension

Replace “filename.extension” to whatever file you are trying to add like “abc.txt”. 

This will add the file you specify to what is called a “staging area” or index. 

Think of the staging area like a section where things are getting set up to be moved to your

repository.


Command-4: git add .

If you want to add everything from the project folder to the staging area this command will do that instead of having to add each file one by one.


Command-5: git add *.txt

If you want to add all .txt files to your staging area this would be the command to use. The extension can be changed to whatever you want.


Command-6: git status

Shows what has already been added to the staging area and what files have been changed that need to be added to the staging area.


Command-7: git reset filename.extension

Removes specified file from the staging area.


Command-8: git rm --cached filename.extension

This will remove the file from the staging area and sets it to be untracked.


Command-9: git commit -m "Description of the commit details"

Takes the files from your staging area and commits them to your local repository.

Command-10: touch .gitignore

This will create a file called .gitignore. You can open that file with a text editor and write the

name of files or folders you want to be ignored from your repository. Ignored files won’t show

up when you run git status to prevent you from committing files you’ve previously said you

don’t want to commit or even know about their changes.


Command-11: git branch branchName

Creates a branch which is a direct copy of your codebase from your previous branch(in most

cases your master branch).


Command-12: git branch -d branch_name

You can delete the branch if something goes wrong or you decide you don’t need that feature or

bug fix any longer.


Command-13: git merge branchName

While inside Master branch you can use this command to take the commits from the branch

currently you were working in and merge them together with the main repository.


Command-14: git remote add origin https://github.com/userName/projectName.git

This adds the location of your remote repository. Everything up until now has been on your

local repository on your computer. 


Command-15: git remote

List of your remote repositories that all are associated with your project.


Command-16: git push -u origin master

This will push your local repository to your remote repository.


Command-17: git clone https://github.com/userName/projectName.git 

This will allow you to clone (or download) the entire project into your working directory.


Command-18: git pull

If you are working on the same codebase with other people, this command will allow you to pull

the latest version from the remote repository and update your local version so you can work

with the latest updates as their changes enter the codebase.


Command-19: git show HEAD

To show the history of recent commit in current checkout branch.


Command-20: Git diff HEAD~commitId1 HEAD~commitId2

To show the difference between different HEAD.


THANKS!!













Comments

Popular posts from this blog

Python namespaces & LEGB rule in Python