All Projects → CodeChefVIT → git-cheatsheet

CodeChefVIT / git-cheatsheet

Licence: MIT license
One stop guide to help solve all your doubts related to Git & GitHub.

Projects that are alternatives of or similar to git-cheatsheet

openmessaging.github.io
OpenMessaging homepage
Stars: ✭ 12 (-61.29%)
Mutual labels:  push, pull
git-pull-or-clone
Ensure a git repo exists on disk and that it's up-to-date
Stars: ✭ 46 (+48.39%)
Mutual labels:  clone, pull
cheat-sheet
collection of cheat sheets
Stars: ✭ 150 (+383.87%)
Mutual labels:  cheatsheet, git-cheatsheet
Hackthebox
Notes Taken for HTB Machines & InfoSec Community.
Stars: ✭ 167 (+438.71%)
Mutual labels:  cheatsheet, star
peek
1-click from git repo to local editor
Stars: ✭ 22 (-29.03%)
Mutual labels:  clone, pull
Git Peek
git repo to local editor instantly
Stars: ✭ 485 (+1464.52%)
Mutual labels:  fetch, clone
gtni
Install your all npm dependencies recursively with gtni while you are doing git clone, fetch or pull
Stars: ✭ 17 (-45.16%)
Mutual labels:  fetch, clone
hackthebox
Notes Taken for HTB Machines & InfoSec Community.
Stars: ✭ 286 (+822.58%)
Mutual labels:  cheatsheet, star
hermes-js
Universal action dispatcher for JavaScript apps
Stars: ✭ 15 (-51.61%)
Mutual labels:  fetch
slicy
A set of typesafe chainable slice helpers to reduce pain of working with slices
Stars: ✭ 18 (-41.94%)
Mutual labels:  helper
IDCardNumber-Validator
An Objective-C & Swift implementation to (check) validate Chinese ID Card No. 身份证号码验证
Stars: ✭ 15 (-51.61%)
Mutual labels:  helper
hms-push-serverdemo-csharp
C# sample code encapsulates APIs of the HUAWEI Push Kit server. It provides many sample programs for your reference or usage.
Stars: ✭ 25 (-19.35%)
Mutual labels:  push
StackFlowView
Enforce stack behaviour for custom UI flow.
Stars: ✭ 35 (+12.9%)
Mutual labels:  push
cheatsheets
📋 Various cheatsheets made while working as a developer
Stars: ✭ 22 (-29.03%)
Mutual labels:  cheatsheet
UCAS-Helper
国科大(UCAS, ucas)校园网登录、课程资源下载、自动评教和分数查询助手
Stars: ✭ 105 (+238.71%)
Mutual labels:  helper
ideas
Идеи по улучшению языка C++ для обсуждения
Stars: ✭ 65 (+109.68%)
Mutual labels:  helper
OpenNefia
(Archived) Moddable engine reimplementation of the Japanese roguelike Elona.
Stars: ✭ 103 (+232.26%)
Mutual labels:  clone
andpush
Android Push Notification in Ruby: The fastest client for FCM (Firebase Cloud Messaging)
Stars: ✭ 83 (+167.74%)
Mutual labels:  push
slick-reference
Slickに関するサンプルやドキュメントを提供します。
Stars: ✭ 64 (+106.45%)
Mutual labels:  cheatsheet
fitch.js
A lightweight Promise based HTTP client, using Fetch API.
Stars: ✭ 35 (+12.9%)
Mutual labels:  fetch

git-cheatsheet

This Repository is a guide to all the git commands you need to use in case any of these situations arise

Index 📚

Basic Commands ✌️

  • Clone a Repository
git init

 Turn an existing directory into a git repository

git clone https://github.com/CodeChefVIT/git-cheatsheet.git

 Replace  url with your required repository url  
  • Set username and emailId
   git config --global user.name "FIRST_NAME LAST_NAME"
   
   git config --global user.email "[email protected]"
  • Pushing to a Repository
  git status
    show modified files in working directory, staged for your next commit
  
  git add .
  git commit -m <commit message>
  git push origin main
   
   To add just one file or a set of files replace the . with your filename in first command
  
  git diff
    diff of what is changed but not staged
  git diff --staged
    diff of what is staged but not yet commited
  git commit -m “[descriptive message]”
    commit your staged content as a new commit snapshot
  
  • Change most recent Git commit message
git commit --amend
  • Check where is your Repository remote
  git remote -v

  Output should have the repository url similar to this 

  origin	https://github.com/CodeChefVIT/git-cheatsheet.git (fetch)
  origin	https://github.com/CodeChefVIT/git-cheatsheet.git (push)
  • Change Remote
git remote set-url origin <new git url>
  • Check logs
    git log 
   
   Output should be something similar 

    commit 82e2a7c46a96b3b4aaf5acbc0cbc218d118aa922
    Author: <User> <45638240+<User>@users.noreply.github.com>
    Date:   Fri May 15 14:52:32 2020 +0530

    <Commit Message>
  • Tracking changes
  git diff
    To track the changes that are yet to staged.

    git diff --staged
      To track the changes that are staged but not committed.
    
    git diff HEAD
      To track the changes after committing a file.
        
    git status
      To know the state of the files in local directory.
    
    git show
     To show all the changes made in the file for each commit
     
  • Ignoring files
    Git can ignore specified files from adding into the remote repository using     gitignore. 
    
    Create .gitignore in the project
    
     vim .gitignore 

Add the filename/directory you want to ignore by the git in the gitignore file

node_modules  

now, when you add the files it ignores node_modules directory in your project.

Back to Index

Branches 🌳

  • Create new branch
   git checkout -b newbranch

   Replace newbranch with your branch name
  • Check current branch
   git branch

   This should list all your branches and highlight the current branch in green
  • Switch to new branch
   git checkout newbranch
  • Push in new branch
    git add .
    git commit -m <commit message>
    git push origin <branch name>

Back to Index

Update forked Repository with original Repository

These steps are to be followed when your forked repository is few commits behind original repository

  1. Check if you have the forked repository added to your remotes.
git remote -v

If you see the forked repository listed in your remotes you can skip to point 3.

  1. Add the forked repository as a remote
git remote add upstream https://github.com/whoever/whatever.git
  1. Fetch changes from forked repository
git fetch upstream

Any new changes and branches from the original forked repository should now be fetched to your local repository.

  1. Rebase your local branch, or merge the changes

You can now choose to either rebase your local branch, or merge the changes from the forked repository into your branch. If you are unsure about which option to pick, you can read more about the differences between rebasing and merging in this article.

Use the following if you want to rebase your branch:

git rebase upstream/main

Or use the merge command if you want to merge instead:

git merge upstream/main

Replace "main" with the name of the branch on the forked repository that you want to rebase or merge with.

Back to Index

Your dev branch is X commits behind and Y commits ahead of main fix

  git checkout main

  git fetch origin main
 
  git checkout dev

  git rebase origin/main

  git checkout main

  git merge --no-ff dev
  
  If you get this message  'Automatic merge failed; fix conflicts and then commit the result'
  
  Check for merge conflicts in code and fix them (main branch should have required files now)
  
  For any such message deleted in  'dev and modified in HEAD. Version HEAD of requirements.txt left in tree' 
  
  File can either be deleted or modified or kept same
  
  git pull origin main (if warning comes)
  
  add , commit , push 

Back to Index

Reverting Commits 😎

These steps are to be followed when you want to revert some unnecessary commits from a specific commit to the latest commit.

     git reset --hard <commit-hash>
      sets the HEAD of the current branch point to that specific commit.
     git push -f
      force pushes the changes to the current branch.

Back to Index

Short hands

    git commit -am <message> 
      adds and commits the changes in a single command
    git push -u origin <branch name>
      use -u (upstream) for pushing your first commit changes into the remote repository
      and later on you avoid origin <branch name>

   git push 
      works fine till the last commit    
    git diff > difference.txt
      If you are feeling hard to track all the changes on console 
      above helps to writes/pipes the differences into specified file (difference.txt) and you can track the changes
      easily

Back to Index

GitHub CLI commands:

List Issues With GitHub CLI
1. gh issue list
list out the open GitHub Issues for our project

2. gh issue list --state "all"
  gh issue list -s "all"
If we want to list out ALL of the issues we could use the “state” flag

3. gh issue list --assignee "n8ebel"
Now, maybe we’ve realized that is too many issues to sort through, so we decide we only want to list out your currently assigned issues.

4. gh issue status
Next, we want to check in on the status of a couple of the issues we created yesterday.  Maybe we don’t remember their exact numbers, but since we created them, we can use the status command to list them at the terminal

5. gh issue list --state "closed"
   gh issue list -s "closed"
After checking in on these issues, we still can’t find the issue we’re looking for, so we might want to check whether it was closed or not.

6. gh issue list --label "bug"
   gh issue list -l "bug"
To list out all of our open bugs, we could filter by the “bug” label defined in our GitHub repo

7. gh issue view "15"
Once we’ve found an issue we want to fix, we might want to assign that issue to ourselves.  Currently, we can’t do that directly from the command line, but we can quickly open the issue from the command line using the “view” command.

8. gh issue create
We can use the gh issue create command to create a new GitHub Issue directly from the command line.

9.  gh issue create -t "Sample Issue Title" -b "Sample issue description"
If you’d like to simplify things a bit, you can specify the issue with the command using additional flags

10. gh pr list
list the open pull requests for our project.

11. gh pr list --state "all"
    gh pr list -s "all"
If we want to list out ALL of the pull requests, both open and closed, we could use the “state” flag

12. gh pr status
Next, we want to check in on the status of a couple of the PRs we created yesterday.  Maybe we don’t remember their exact numbers, but since we created them, we can use the status command to list them at the terminal

13. gh pr list --state "closed"
    gh pr list -s "closed"
After checking in on these PRs, we still can’t find the pull request we’re looking for, so we might want to check whether it was closed or not.

14. gh pr view "14"
Once we’ve found a PR we want to review, we might want to assign that PR to ourself.  Currently, we can’t do that directly from the command line, but we can quickly open the PR from the command line using the view command.

15. gh pr checkout
Check out pull requests locally.

16. gh pr create
Create a new pull request.

17. gh pr checks
View your pull requests’ checks.

18. gh release create
Create a new release

19. gh alias set
Create a shortcut for a gh command.

Back to Index

Signing Commits

These steps are to be followed when you want to sign your current commit.

     git commit --ammend --signoff
      for signing the current commit
     git push -f
      force pushes the changes to the current branch.

Back to Index

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].