Git and Github


Git and GitHub /bitbucket and Gitlab:-
For Practice -->https://learngitbranching.js.org/

Git: Version control system

Share your code

Maintain the history of code changes, who, where, and when 

Multiple people working on the same project

.git --> hidden file, where all the history gets saved

https://git-scm.com/download/win --> To Download Git

write git in the cmd to check if it is installed properly

git init --> to initialize git in that project or folder=> initialize empty git repository in the folder where you did git init


now git will be like hey ankit you have some changes in your project please make sure to click a picture of it , so other people are aware that you made this change.

pwd --> pgitrint working directory

ls--> list all the folders

mkdir  dirName--> make a directory with name dirName

cd dirName --> change directory or come inside the dirName

touch fileName.txt --> to create a file


ls -a --> Show me the list of hidden file

ls .git --> to see what is inside this .git hidden folder

rm dir  dirName-> to remove the directory if it is empty

rm filename -> to remove any file


to rename files mv oldfile.txt newfile.txt


The command "rm -rf" is used to recursively force remove files and directories in Unix-like systems. Here's a breakdown of the command:

  • "rm" stands for remove.
  • "-rf" are command options:
    • "-r" indicates recursive removal, which means deleting directories and their contents.
    • "-f" stands for force removal, which suppresses any prompts or warnings.

When combined, "rm -rf" will remove files and directories forcefully without asking for confirmation.


cat filename

The cat command is a commonly used command in Unix-like systems that is short for "concatenate." Its primary purpose is to display the contents of files on the terminal or concatenate multiple files together and display their combined contents.

Here are some common usages of the cat command:

  1. Display the contents of a file:

    bash
    cat filename

    This command will output the contents of the specified file (filename) to the terminal.

  2. Concatenate multiple files:

    bash
    cat file1 file2 file3 ...

    This command will concatenate the contents of multiple files (file1, file2, file3, etc.) and display their combined contents on the terminal. The files will be concatenated in the order they are listed on the command line.

  3. Create a new file by combining existing files:

    bash
    cat file1 file2 > newfile

    This command will concatenate the contents of file1 and file2 and redirect the output to a new file called newfile. If newfile already exists, it will be overwritten.

  4. Append the contents of a file to an existing file:

    bash
    cat file1 >> existingfile

    This command will append the contents of file1 to the end of existingfile. If existingfile doesn't exist, it will be created.

The cat command also has several other options and functionalities, such as numbering lines (-n option) or displaying non-printing characters (-v option). You can refer to the cat command's manual page by typing man cat in the terminal for more information and additional usage examples.



VIM COMMANDS

vi filename.txt/extension --> to open the file in the vim

to insert text--> go to insert mode by pressing "i"

ESC-->  to come out of the insert mode;

:w --> to save your changes

:q --> quit vim or close vim

:x --> save and close vim


GIT COMMANDS

git status --> to know what files are added/modified or removed or whatever change is done in the project that is not currently saved

--> Untracked files it will show

Story--> Suppose tum kisi shaadi mein gaye ho toh couple stage par hota hai for a photoshoot, toh guest stage par jatey hai  fir unki pics click hoti hai aur fir wo memories create ho jati hai. or will be saved in the history of the wedding in the photo album

Again

--> So people whose photograph is not taken yet will go to the stage --> ye kaise pata chala git status se ki kis kis ki photo click nahi hui hai, we got untracked files or people jinki photo click nahi hui
--> git add . or git add specific fileName --> unko stage par bulaney k liye --> after git add now the people are on stage now,  means --> everything in current dir jiski history create nahi hui. put all those files into the staging area.

but agar unko stage se hatana hai wo galti se stage par aa gye hai  --> git restore --staged filename.txt--> now they are outside the stage

--> git commit -m "message likh do for more details"  here "m" stands for message --> once we did git commit photograph got clicked  





git log:- to see the log of all commits / to see all commits made in the history

suppose you deleted one file and made  a commit, but Now you want to go back to the condition of the previous commit 
so you can delete the delete commit, you can not remove any commit from the middle, because they are created on top of each others hash id,

copy the commit below the one you want to delete

git reset 183ba3eb5edd9121c83cdbef9a4ffad1b6f833c1

the above commit "183ba3eb5edd9121c83cdbef9a4ffad1b6f833c1" changes are now in the unstaged area

Imagine you don't want to delete them and say them YOU ARE THE FEW PEOPLE WHOSE PHOTO IS NOT YET TAKEN go the backstage, we will call you when we need you ---> STASH
I don't want to commit it also I don't want to lose these changes.

git add .
git stash


git stash pop --> Hey All the people on backstage come back to the stage

git stash clear --> Hey you all mf  your photo is not yet taken go away, fuck you all.

git remote add origin url --> to connect with the remote repository 

git remote -v

git push origin master


git branch branchName--> to create a branch with branchName

git checkout branchName--> now head is pointing to branchName

branches 










 git merge branchName ---> to merge the code in the main

fork--> create a copy  because you can't make changes to anyone account 

upstream url --> from where you have forked the project is known as upstream url
git remote add upstream url

For every new feature create a new branch, never push directly to main branch.

git fetch --all --prune --> prune means the ones which are deleted also fetch them
git reset --hard upstream/main

git pull upstream main
git push origin main

Squash commit  --->
git rebase -i 
pick --> I want this commit
s--> Squash this commit in a pick one


Github: Allows us to host our repositories where our all changes are saved.

Comments

Popular posts from this blog

TO the new

4048