Git & Github - 2

Kusuma VKusuma V
3 min read

First steps in Git

create a folder -mkdir sample

git init -to create a git local repository

untracked files (red color)tacked files (green color)local repo
file.txt (file created)in order to know to where it is we have to use
git statusgit add . or git add * (files will move)git commit -m "commit message"
  1. git commit –a –m sample (here we can comment directly to local repo without staging area but this scenario work only already file is committed and just now re-modified it)

  2. git remote add sample github url

  3. If you want to see about the how many commit of particular one commit -git show commit id

  4. if you want to just see the file names only .then git show --pretty="" --name-only commit id

Create a folder & within it create file -mkdir sample1

a.cd sample1 ( directory will change )

b. How to initialize git git init sample1 ( file/folder)

c. cat > sample1

d. come to root user cd /

e. add file to git git add file name

f. to check status git status

g. to commit git git commit -m "commit message"

h.to restore previous message git reset --hard HEAD (latest commit)

i. to see all executions git logs

j. to see only few executions files git log -n (n = number)

k. If you want to see about the how many commit of particular one commit “git show ea3a36dfg” (each3623dh) _ it’s a commit ID

l. to see one line info git log -oneline

m. to clean file git clean -n

n. to forcefully remove lines git clean -f

o. git reset filename ( this will get from staging area to working area)

p. if want to get back the only one file to be reset that "git reset filename"

q. git revert 99ff09sdf0sfd will delete the files of that particular commit

***we cannot use git revert for older commit


.gitignore

why .gitignore ?

sometime we don't want to commit the files which are generated by IDK like .project and .classpath files are some node modules folders like node_modules folder in to a git repository. To ignore this files and folders to commit we will create one file called .gitignore and we will keep the file names and directory names which we don't want to commit as follows

what ever the which we are don't want to commit as a part of source code we create the .gitignore file and we are going to keep it there

Here we have kept file & folder in working area as shown in below

in .gitignore file we can see above rest of the file .it checks with vi editor sshown below

Now check git status command

Commit & push it we can see it in remote repo

0
Subscribe to my newsletter

Read articles from Kusuma V directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kusuma V
Kusuma V

Passionate about staying updated with the latest advancements in cloud computing and DevOps practices, I am committed to driving innovation and delivering value through technology.