Github all commands you need to know

Here is a cheatsheet for all the GitHub commands.


1. git help

Take help from GitHub help section for different commands and other errors


2. 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. This means “Initialise a local Git repository”.


3. git clone [ URL ]

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”.


4. git add .

This command adds files to the staging area. you can use ‘ . ‘ or ‘ * ‘ to add your all files.


5. git add [ FILE NAME ]

This command adds a file to the staging area.


6. git add -A

Add all new and changed files to the staging area


7. git add –all

To add all files of current directory to staging area.


8. git add *.txt

To add all text files of the current directory to staging area.


9. git add src/*.txt

To add all text files of a particular directory(src) to staging area.


10. git add src/

To add all files in a particular directory(src) to staging area.


11. git add “*.txt”

To add text files of entire project to staging area.


12. git status

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


13. git branch

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.


14. git branch [ NEW_BRANCH_NAME ]

create a new branch


15. git branch -d [ BRANCH_NAME ]

If you want to delete a branch, follow this GitHub command.


16. git branch -a

List all branches (local and remote)


17. git branch -r

To look at all the remote branches.


18. git branch -m [ OLD_BRANCH_NAME ] [ NEW_BRANC_NAME ]

This command is use to rename a local branch.


19. git push origin –delete [ BRANCH_NAME ]

If you want to delete a remote branch. you can follow above command.


20. git checkout [ BRANCH_NAME ]

If you want to switch already created branch, you need to follow above command.


21. git checkout -b [ NEW_BRANCH_NAME ]

If you want to create a new branch and want to switch to that branch, you can follow above command.


22. git checkout -b [ BRANCH_NAME ] origin/[ BRANCH_NAME ]

This command represent, clone a remote branch and switch to it.


23. git checkout –

Switch to the branch last checked out.


23. git checkout — [file-name.txt]

Discard changes to a file.


25. git checkout –license

To Blow away all changes since the last commit of the file.


26. git stash

Git stash is a command, that temporarily save your modified files.


27. git stash list

If you want to see what are the stashes file, use this above GitHub command.


28. git stash apply

If you want to apply your changes to your branch, use this above command.


29. git stash pop

This command restores the most recently stashed files.


30. git stash drop

This command discards the most recently stashed change-set.


31. git stash clear

Remove all stashed entries – GitHub commands.


32. git log

If you want to see the previous commits with head commits, use this command. It means view details.


33. git log –summary

If you want to view changes in detailed.


34. git log –oneline

View changes in briefly.


35. git log –follow[ FILE ]

This command lists version history for a file, including the renaming of files also.


36. git show [ COMMIT ]

This command shows the metadata and content changes of the specified commit.


37. git reset [ FILE ]

This command un-stages the file, but it preserves the file contents.


38. git reset [ COMMIT ]

This command undoes all the commits after the specified commit and preserves the changes locally.


39. git reset head license

To undo staging of the file that was added in the staging area.


40. git reset –hard HEAD~1

If you need to reset your commit. It means reset the commit you want to delete.


41. git reset –hard HEAD^

To undo last commit and remove file from the staging area as well(In case we went horribly wrong).


42. git reset –soft HEAD^

To undo last commit and bring file to staging area.


43. git reset –hard HEAD^^

To undo last 2 commits and all changes – GitHub commands.


44. git commit -m “initial commit”

To commit our changes(taking a snapshot) and providing a message to remember for future reference.


45. git commit -a

This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.


46. git commit –amend

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.


47. git push

Push changes to remote repository (remembered branch)


48. git push origin [ BRANCH_NAME ]

Push a branch to your remote repository


49. git push -u origin [ BRANCH_NAME ]

Push changes to remote repository and remember the branch


50. git push origin –delete [ BRANCH_NAME ]

push changes and Delete a remote branch


51. git push –all origin

This command pushes all branches to your remote repository.


52. git pull

Update local repository to the newest commit


53. git pull origin [ BRANCH_NAME ]

Pull changes from remote repository


54. git remote add origin ssh://git@github.com/[ USERNAME ]/[ REPOSITORY_NAME ].git

Add a remote repository – GitHub commands.


55. git remote set-url origin ssh://git@github.com/[ USERNAME ]/[ REPOSITORY_NAME ].git

Set a repository’s origin branch to SSH


56. git tag

To see the list of available tags.


57. git tag -a [TAG NAME OR VERSION – ex- V1.2.0.0]

We use tags to manage our releases. To create a tag use above command.


58. git verify-tag [TAG NAME OR VERSION – ex- V1.2.0.0]

If you want to confirm or verify a tag, you can use git verify-tag command.


59. git push –tags

To push the tags to remote repository.


60. git merge [ BRANCH_NAME ]

Merge a branch into the active branch


61. git merge [ SOURCE_BRANCH ] [ TARGET_BRANCH ]

Merge a branch into a target branch – GitHub commands.


62. git rm -r [file-name.txt]

Remove a file or a folder. This command deletes the file from your working directory and stages the deletion.


63. ls

To see directories and files in the current directory. 


64. git citool

git citool is a graphics alternative of a Git commit.


65. git mv [ OLD_FILE_NAME ] [ NEW_FILE_NAME ]

If you want to rename a git file, you can use this command.


66. git cherry-pick [ COMMIT-HASH ]

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.


67. git archive –format zip HEAD > archive-HEAD.zip

If you want to combine your multiple files to a single file, this is the command for that. This will create a zip.


68. git bisect start

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.


69. git bisect good a123

How to bisect know the commit is a good commit.


70. git bisect bad d123

How to bisect know commit is a bad commit – GitHub commands.


71. git fetch origin
72. git fetch origin [ BRANCH_NAME ]
73. git fetch [alias]

The git fetch command downloads commits, files, and refs from a remote repository into your local repo.


74. git fetch –all

If you want to fetch all branches on git – GitHub commands.


75. git rebase

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.


76. git config

Basic configure GitHub. like you email, username. It means, To set the basic configurations on GitHub like your name and email.


77. git config –-global user.name “Build IT Masters”

Git config username global on git | Set username on git


78. git config –-global user.email info@builditmasters.com

Git config email global on git


79. git config –global user.password “builditmasters

Git config password global on git


80. git config –-global color.ui true

Different colors on command line for different outputs.


81. git diff

To figure out what changes you made since last commit. This command shows the file differences which are not yet staged.


82. git diff –staged

This command shows the differences between the files in the staging area and the latest version present.


83. git diff [ FIRST_BRANCH ] [ SECOND_BRANCH ]

This command shows the differences between the two branches mentioned.


84. git clean

Removes untracked files from the working directory. This is the logical counterpart to git reset, which (typically) only operates on tracked files.


85. git reflog

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.


86. git remote

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.


87. git revert

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.

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x