Here is a cheatsheet for all the GitHub commands.
Take help from GitHub help section for different commands and other errors
To create a local git repository for us in our store folder. This will help to manage the git commands for that particular repository. This means “Initialise a local Git repository”.
This command is used to obtain a repository from an existing URL. you can get the url from the GitHub. We can say “Create a local copy of a remote repository”.
This command adds files to the staging area. you can use ‘ . ‘ or ‘ * ‘ to add your all files.
This command adds a file to the staging area.
Add all new and changed files to the staging area
To add all files of current directory to staging area.
To add all text files of the current directory to staging area.
To add all text files of a particular directory(src) to staging area.
To add all files in a particular directory(src) to staging area.
To add text files of entire project to staging area.
To see whats changed since last commit.It shows all the files that have been added and modified and ready to be committed and files which are untracked
To manage your branches, you can use git branch commands. There are few command that you need to learn about. Above command is for list the all branches you have. If you want to create a new branch follow the below code.
create a new branch
If you want to delete a branch, follow this GitHub command.
List all branches (local and remote)
To look at all the remote branches.
This command is use to rename a local branch.
If you want to delete a remote branch. you can follow above command.
If you want to switch already created branch, you need to follow above command.
If you want to create a new branch and want to switch to that branch, you can follow above command.
This command represent, clone a remote branch and switch to it.
Switch to the branch last checked out.
Discard changes to a file.
To Blow away all changes since the last commit of the file.
Git stash is a command, that temporarily save your modified files.
If you want to see what are the stashes file, use this above GitHub command.
If you want to apply your changes to your branch, use this above command.
This command restores the most recently stashed files.
This command discards the most recently stashed change-set.
Remove all stashed entries – GitHub commands.
If you want to see the previous commits with head commits, use this command. It means view details.
If you want to view changes in detailed.
View changes in briefly.
This command lists version history for a file, including the renaming of files also.
This command shows the metadata and content changes of the specified commit.
This command un-stages the file, but it preserves the file contents.
This command undoes all the commits after the specified commit and preserves the changes locally.
To undo staging of the file that was added in the staging area.
If you need to reset your commit. It means reset the commit you want to delete.
To undo last commit and remove file from the staging area as well(In case we went horribly wrong).
To undo last commit and bring file to staging area.
To undo last 2 commits and all changes – GitHub commands.
To commit our changes(taking a snapshot) and providing a message to remember for future reference.
This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.
Passing the –amend flag to git commit lets you amend the most recent commit. This is very useful when you forget to stage a file or omit important information from the commit message.
Push changes to remote repository (remembered branch)
Push a branch to your remote repository
Push changes to remote repository and remember the branch
push changes and Delete a remote branch
This command pushes all branches to your remote repository.
Update local repository to the newest commit
Pull changes from remote repository
Add a remote repository – GitHub commands.
Set a repository’s origin branch to SSH
To see the list of available tags.
We use tags to manage our releases. To create a tag use above command.
If you want to confirm or verify a tag, you can use git verify-tag command.
To push the tags to remote repository.
Merge a branch into the active branch
Merge a branch into a target branch – GitHub commands.
Remove a file or a folder. This command deletes the file from your working directory and stages the deletion.
To see directories and files in the current directory.
git citool is a graphics alternative of a Git commit.
If you want to rename a git file, you can use this command.
This command is the most important command in your programming life. You can pick any commit from your branch that you want to merge with any other branches. git cherry-pick doesn’t change or modify repository history. git cherry-pick does only adds to the history.
If you want to combine your multiple files to a single file, this is the command for that. This will create a zip.
This command is to find your bad commits. Do you know, With Git bisect command you can narrow down the broken code within a few minutes. To start the git bisect use this above command.
How to bisect know the commit is a good commit.
How to bisect know commit is a bad commit – GitHub commands.
The git fetch command downloads commits, files, and refs from a remote repository into your local repo.
If you want to fetch all branches on git – GitHub commands.
Move all changes to master which are not in origin/master to a temporary area. Run all origin master commits and Run all commits in the temporary area on top of our master one at a time, so it avoids merge commits.
Basic configure GitHub. like you email, username. It means, To set the basic configurations on GitHub like your name and email.
Git config username global on git | Set username on git
Git config email global on git
Git config password global on git
Different colors on command line for different outputs.
To figure out what changes you made since last commit. This command shows the file differences which are not yet staged.
This command shows the differences between the files in the staging area and the latest version present.
This command shows the differences between the two branches mentioned.
Removes untracked files from the working directory. This is the logical counterpart to git reset, which (typically) only operates on tracked files.
Git keeps track of updates to the tip of branches using a mechanism called reflog. This allows you to go back to change-sets even though they are not referenced by any branch or tag.
A convenient tool for administering remote connections. Instead of passing the full URL to the fetch, pull, and push commands, it lets you use a more meaningful shortcut.
Undoes a committed snapshot. When you discover a faulty commit, reverting is a safe and easy way to completely remove it from the code base.
Thank you for reading. If you are interesting on my article, make sure to follow my other articles as well. Make sure to leave a comment.
- Android Studio Articles – https://builditmasters.com/category/android-studio/
- Android Studio Firebase Tutorial – https://builditmasters.com/category/android-studio-firebase-tutorial/
- C Programming – https://builditmasters.com/category/programming/
- Flutter – https://builditmasters.com/category/flutter/
- GitHub Tutorials – https://builditmasters.com/category/github/
- Java Programming – https://builditmasters.com/category/java-programming/
- MERN / MEVN Stacks – https://builditmasters.com/category/mern_mevn_stacks/
- Tech News – https://builditmasters.com/category/tech-news/
- Theory Lessons – https://builditmasters.com/category/theory-lessons/
- Adobe Tutorials – https://builditmasters.com/category/adobe-tutorials/
- Best Website for Programming – https://builditmasters.com/category/best-website-for-programming/
- Different Programming Styles – https://builditmasters.com/category/different-programming-styles/
- Earn Money – https://builditmasters.com/category/earn-money/
- Social Word – https://builditmasters.com/category/social-world/