You are on page 1of 5

GIT GUIDE

LOCAL FILES -> STAGING AREA ->COMMIT CHANGES/


GITHUB(PUSH/PULL)
(STEP ZERO) First most step for all git experiments: MAKE A FOLDER>OPEN
FOLDER> CREATE A FILE> ADD CONTENT TO FILE> RIGHT CLICK AND SELECT
GIT BASH HERE.

EXPERIMENT 1: to stage and commit files

STEP ZERO

git init

git add . OR git add file.txt

git commit -m “commit message”

EXPERIMENT 2: to create a feature branch and merge with master branch

STEP ZERO

git init

git add .

git commit -m “commit message”

git checkout -b branchname //switches to feature branch

//open file, and add more content

git add .

git commit -m “feature branch commit message”

git checkout master


git merge branchname
//check the file to confirm if feature branch commit content is added to master branch
____________________________________________________________________________

EXPERIMENT 3:

STEP ZERO
git init
//add contents to file
git add .
git commit -m “master commit”
// make changes
git stash save “message”

git checkout -b branchname

git stash apply

git add .

git commit -m “branch commit”

//optional git checkout master


____________________________________________________________________________

EXPERIMENT 4: cloning files for github

Create a folder and open it, right click and open git bash here

//if git url is given then use that, if not then go to browser, search github, log in, open one
repository( search some title ex: notes, and click open one note) copy the link from chrome

In git bash:

git clone “paste link”


// this will download all the files from that repository to your computer folder

____________________________________________________________________________
EXPERIMENT 6: merge with message

STEP ZERO
git init

git add .

git commit -m “message”

git checkout -b branchname


// make changes to file

git commit -m “feature branch commit message”

git checkout master

git merge branchname -m “message”


// this will attach a message to your merge just like how you attach a message to your commit

____________________________________________________________________________

EXPERIMENT 7: creating tags

STEP ZERO

git init

git commit -m “message”

git log
//copy commit id from here, select the id, right click and copy

git tag tagname(ex: tagv1, v1, tagv1.0, anything) //creates a tag for the latest commit
OR

git tagname “paste commit id here” // to create a tag for a specific commit
//right click and paste

____________________________________________________________________________
EXPERIMENT 8:

STEP ZERO

git init

git add .

git commit -m “message”


//add more content in file

git commit -m “message 2”


//more content

git commit -m “message” //repeat this for 5-6 times

git log
// choose one commit id from the first and one commit id from the last (identify which is first and
last commit by referring to commit message otherwise will get confused, example i choose: third
commit and 5th commit)

git cherry-pick (id1)^..(id2)


//replace brackets and id, no space before or after ^.. Otherwise error

//open your file to see what you've cherry picked

____________________________________________________________________________

EXPERIMENT 9:

STEP ZERO

git init

git add .

git commit -m “message” //if possible make changes in file and make more commits, 3+ commit

git log
//copy commit id from here
METHOD 1: git show “paste commit id here” //no double quotes
OR
METHOD 2: git log -n 1 “paste commit id here” //no double quotes
____________________________________________________________________________

EXPERIMENT 10:

STEP ZERO
git config –global user.name “lekha”

git init

git add .

git commit -m “message” // make more changes in the file and commits

git log --author=”lekha” --since=”2024-02-21” --until=”2024-02-21”

____________________________________________________________________________

EXPERIMENT 11:

STEP ZERO

git init

git add .

git commit -m “message”


git add .
//make at least 6 changes and 6 commits to the file

git log n
//n = number of commits you want to display, if you have made N commits, then the maximum
n<=N, ex: you made 6 commits, you can give n as 1,2,3,4,5,6 and not more. Choose any
number.

You might also like