Most Useful GIT Commands

Share via:

Most Useful GIT Commands

In this article,we will see Most useful GIT Commands.

SNO    USE   COMMAND
1 See the version of GIT git –version
2 To Configure the username and email git config –global user.name “Ram” git config –global user.email “rameshatchala.ktexperts@gmail.com”
3 Verify Username and email configurations git config –list
4 Set color for highlighting output git config –global color.ui true
5 Set the Date date +%T -s”21:43:00″
6 Verify Date date
7 Initialize GIT Repository git init
8 See the status of GIT git status
9 Add file to staging area git add <filename> git add * git add . git add –all git add ktexperts/ git add docs/*.txt git add “*.txt”
10 Commit the file to Local Repository git commit -m “Commit message”
11 See the list of all commits git log
12 See the content of Commit ID git show <commit ID>
13 Connect your Local Repository to Central Repository (GitHub) git remote add origin <central repository URL> git remote add origin https://github.com/Ramesh-Ktexperts/centralgit.git
14 Push commits to the master branch of central repository (GitHub) git push origin master
15 Pull commits from master branch of central repository git pull origin master
16 See the latest commit git log -1
17 See all the list of commits in a summarized manner git log –oneline
18 Pick commit based on the commit message git log –grep <Any word of commit message> git log –grep “london”
19 Ignore file while commiting .gitignore
20 To see the list of available branches in Local Repository git branch
21 Create a new branch git branch <branch name> git branch Ktexperts-New-Branch
22 Switch to another branch git checkout <branch name> git checkout Ktexperts-New-Branch
23 Merging the commits from branch “Ktexperts-New-Branch” to “master” git merge Ktexperts-New-Branch (be inside master)
24 See the list of all configured Central repositories /Remote repositories (GitHub) git remote -v
25 Remove the central repository git remote remove origin
26 Rename th central repository/remote repository (origin to destination) git remote rename origin destination
27 Push commits to the master branch of central repository (GitHub) git push destination master (If change destination)
28 Pull commits from master branch of central repository (GitHub) git pull destination master (If change destination)
29 Reset your Local Repository URL (Instead of Drop) git reset –hard origin/master
30 Create and switch to a new branch git checkout -b <branchname>
31 Delete the particular feature branch(Be inside master branch) git branch -d <branchname>
32 Push all branches to Central repository/Remote Repository (GitHub) git push –all origin
33 Delete a branch on a Central Repository /Remote Repository git push origin <branchname>
34 View all the merge conflicts git diff
git diff –base <filename>
35 Create a git stash with name git stash save “my_stash_name” git stash save “rammy-stash”
36 Send content of task to saved Stash Repository (Cut and Paste) git stash push -m “stash repository name” again git stash push -m “rammy-stash” again
37 Stash a specific file git stash push -m “new task” ram1
38 Stash untracked files git stash –include-untracked or git stash -u
39 Stash untracked and modified files git stash
40 stash your current changes into a specific branch. git stash branch <branch_name> git stash branch ram1
41 stash your current changes into a specific branch. git stash branch ram2 stash@{0}
42 See stashed items list git stash list
43 Apply stashed items git stash apply stash@{stash_index} git stash apply stash@{0}
44 applies your changes to your current working directory but it also deletes the stash from the stash stack git stash pop stash@{stash_index} git stash pop stash@{0}
45 to see the differences between your stash and the most recent commit of your branch git stash show stash@{stash_index} git stash show stash@{0}
46 see all the differences including content git stash show -p stash@{stash_index} git stash show -p stash@{0}
47 Clean the specific stash git stash drop stash@{stash_index} git stash drop stash@{0}
48 Clean the stash repository git stash clear
49 Delete Snapshot from Staging Area git reset <file name> git reset .
50 Delete file from both areas (Staging Area & Work Space) git reset –hard
51 Revert to a existing commit git revert <Commit ID> git revert 7ad3592
52 clean unnecessary files and optimize the local repository. git gc
53 Remove a file from Local Repository git rm <filename>
54 Delete All untracked files git clean -n ( show the confirmation message to delete untracked files ) git clean -f ( Delete all untracked files forcefully)
55 Apply tag for Commit ID git -a <tag name> -m <tag message> <commit ID> git tag -a kt_tag -m My_important_commit 1d0f9fe
56 To show the content of commit ID by using tag git show <tag name> git show kt_tag
57 See the list of tags git tag
58 Push all tags to Central Repository/Remote Repository git push –tags origin
59 Delete a tag git tag -d <tag name> git tag -d kt_tag
60 Create Clone Repository by using URL git clone <Central Repository (GitHub) URL> git clone https://github.com/Ramesh-Ktexperts/AWS.git

 

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

Facebook : https://www.facebook.com/ktexperts/
LinkedIn   : https://www.linkedin.com/company/ktexperts/
Twitter     : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

One thought on “Most Useful GIT Commands

Leave a Reply to santhi Cancel reply