0% found this document useful (0 votes)
12 views

Git Commands

Git note

Uploaded by

Mehedi Hasan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Git Commands

Git note

Uploaded by

Mehedi Hasan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Git commands

● GIT WORKING DIR

1- To initialize/start the git


git init

2- To see the status of the code in which workflow


git status

3- To add all the file from working directory to staging area


git add .

4- To add specific file from working directory to staging area


git add file_name

5- to see the difference between present file and previous file


git diff

6- to get back to the previous file before the recent edit


git checkout your_current_file_name

7- to get a specific commit file version


git checkout commit_id

4- ( to add code from staging area to local repo with a message)


git commit -m “commit_message”

5 - ( shows the info regarding commit ex - commit id, user name, user email
and other info regarding error and code)
git log --oneline

6- ( to show the info regarding particular commit id ex - code and changes in


code)
git show commit_id
● GIT CENTRAL REPO (GITHUB)

7- ( to connect local repo to central repo )


git remote add origin github_repo_url

8- ( to put the code from local repo to central repo into master branch )
git push -u origin master

9- ( to take the code from central repo to local repo from master branch )
git pull origin master

10- (to ignore the specific file while committing to local repo)
(Ex - vi .gitignore
and enter file type you want to ignore while commit ex- *.json, *.phy , *.html)

● GIT BRANCH AND MERGE

11- To see which branch you are in


git branch

12- To create a new branch


git branch branch_name

13- to change/switch to a branch


git checkout branch_name

14- to delete a branch after merging


git branch -d branch_name

15- to delete a branch forceful before merging


git branch -D branch_name

16- to merge to two branches of a repo


git merge branch_name
● GIT STASHING

17- to stash a file/item


git stash

18- to see what inside stash


git stash list

19- to use a file/item from stash


git stash apply stash@{1}

20- to clear or delete a stash item


git stash clear

● GIT STAGING

21- to put code file back from staging to working directory


git reset file_name
Then
git reset .

22- to put code file back from staging to working directory


git restore --staged file_name

● GIT REVERT

22- to revert to the previous file after a wrong commit


git revert wrong_commit_id

NOTE:- add a message “please ignore previous commit”

23- to delete untracked files


git clean -n
Then
git clean -f
● GIT TAGS

24- to add tags to your commit


git tag -a tag_name -m “message”

25- to the available tags / tag names


git tag

26- to see the commit related to that tag


git show tag_name

27- to delete the tag


git tag -d tag_name

● GIT CLONING

28- to clone a file/repository from central repo to local repo


git clone repo_url

You might also like