List of useful Github Commands - GeeksforGeeks

04 Aug, 2021
Github is a distributed version control system which helps to manage the repositories. 
These are a list of few commands that you can use frequently on github(git bash)  
1.git help
Take help from github help section for different commands and other errors  
2.git config
To set the basic configurations on github like your name and email.  
3.git config –-global user.name “Ashish Madaan”
Sets configuration values for your user name on git.  
4.git config –-global user.email ashishmadaan6@gmail.com
Sets configuration values for your user email on git.  
5.git config –-global color.ui true
To see different colours on command line for different outputs.  
6.mkdir store
Create a directory if not created initially.  
7.cd store
To go inside the directory and work upon its contents.  
8.git init
To create a local git repository for us in our store folder.This will help to manage the git commands for that particular repository.  
9.git status
To see whats changed since last commit.It shows all the files that have been added and modified and ready to be commmitted and files which are untracked  
10.git add Readme.txt
To add a file Readme.txt to the staging area to track its changes.  
11.git commit -m “Created a Readme.txt”
To commit our changes(taking a snapshot) and providing a message to remember for future reference.  
12.git log
To check the history of commits for our reference. 
Different ways to use add command:  
13.git add
To add a specific list of files to staging area.  
14.git add --all
To add all files of current directory to staging area.  
15.git add *.txt
To add all text files of the current directory to staging area.  
16.git add docs/*.txt
To add all text files of a particular directory(docs) to staging area.  
17.git add docs/
To add all files in a particular directory(docs) to staging area.  
18.git add “*.txt”
To add text files of entire project to staging area. More Commands:  
19.git diff
To figure out what changes you made since last commit.  
20.git reset head license
To undo staging of the file that was added in the staging area.  
21.git checkout –license
To Blow away all changes since the last commit of the file.  
22.git commit -a -m “Readme.md”
To add any of our tracked files to staging area and commit them by providing a message to remember.  
23.git reset –soft HEAD^
To undo last commit and bring file to staging area.  
24.git reset –hard HEAD^
To undo last commit and remove file from the staging area as well(In case we went horribly wrong).  
25.git reset –hard HEAD^^
To undo last 2 commits and all changes.  
26.git remote add origin https://github.com/madaan123/MyAlgorithms.git
This commands make a bookmark which signifies that this particular remote refers to this URL. This remote will be used to pull any content from the directory and push our local content to the global server.  
27.git remote add <address> 
To add new remotes to our local repository for a particular git address.  
28.git remove rm
To remove a remote from our local repository.  
29.git push -u origin master
To push all the contents of our local repository that belong to master branch to the server(Global repository).  
30.git clone https://github.com/madaan123/MyAlgorithms.git
To clone or make a local copy of the global repository in your system (git clone command downloads the repository and creates a remote named as origin which can be checked by command – git remote -v).  
31.git branch Testing
To create a new branch named as Testing.  
32.git branch
To see all the branches present and current branch that we are working on.  
33.git checkout Testing
To switch to branch Testing from master branch.  
34.ls
To see directories and files in the current directory.  
35.git merge Testing
To merge Testing branch with master branch.  
36.git branch -d Testing
To delete Testing branch.  
37.git checkout -b admin
To create a new branch admin and set it as current branch.  
38.git branch -r
To look at all the remote branches.  
39.git branch -D Testing
To forcefully delete a branch without making commmits.  
40.git tag
To see the list of available tags.  
41.git checkout v0.0.1
To set the current tag to v0.0.1.  
42.git tag -a v0.0.3 -m “version 0.0.3”
To create a new tag.  
43.git push –tags
To push the tags to remote repository.  
44.git fetch
To fetch down any changes from global repository to current repository  
45.git rebase
Three tasks are performed by git rebase  
Move all changes to master which are not in origin/master to a temporary area.Run all origin master commits.Run all commits in the temporary area on top of our master one at a time, so it avoids merge commits.
Move all changes to master which are not in origin/master to a temporary area.
Run all origin master commits.
Run all commits in the temporary area on top of our master one at a time, so it avoids merge commits.
This article is contributed by Ashish Madaan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. 
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
jasawatsandeep31
GBlog
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 10 Front End Developer Skills That You Need in 2022
DSA Sheet by Love Babbar
6 Best IDE's For Python in 2022
A Freshers Guide To Programming
ML | Underfitting and Overfitting
Virtualization In Cloud Computing and Types
Top 10 Programming Languages to Learn in 2022
What is web socket and how it is different from the HTTP?
Top Selenium Frameworks You Should Know
Introduction to Hill Climbing | Artificial Intelligence