Code Monkey home page Code Monkey logo

git's Introduction

Git command line

HTTPS

https://github.com/alexb017/namerepo.git

SSH

[email protected]:alexb017/namerepo.git

Quick start

...or create new repository on the command line

echo "# cmd" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/alexb017/namerepo.git
git push -u origin main

..or push an existing repository from the command line

git remote add origin https://github.com/alexb017/namerepo.git
git branch -M main
git push -u origin main

Change connection from SSH to HTTPS

git remote set-url origin https://...
git remote set-url --push origin https://...

View the configured remotes with git remote -v.

Git Commands

  1. init - Initialize a new Git repository.
  2. clone - Create a local copy of the repository, including all of its history and branches. git clone <repo-link>
  3. add - Add the specified file(s) to the staging area, where they will be included in the next commit. git add index.html
  4. commit - Record the staged changes and any additional changes made since the last commit, along with a commit message describing the changes. git commit -m "Fix"
  5. push - This sends the local commits to the specified remote repository, updating the branch on the remote with the new commits. git push origin master
  6. pull - Retrieve the latest commits from the specified remote repository and merges them into the current branch. git pull origin main
  7. branch - Can be used to list the available branches in a repository, create a new branch, or delete an existing branch. git branch new-branch
  8. checkout - Allow you to switch to a different branch in the repository and make it the current working branch. git checkout main
  9. merge - Combines the changes from one branch into another branch, creating a new commit that reflects the merged changes. git merge branch-name
  10. status - Display current branch, any staged or unstaged changes, and any untracked files. git status
  11. rebase - Let's say you have made some changes on an "XYZ" branch that you want to incorporate into the "main" branch. You can use git rebase to reapply your changes on top of the main branche.
git checkout main
git pull
git checkout xyz
git rebase main
  1. stash - If you changes are not ready to commit but you want to work an a different branch, you can temporarily save your changes for later use and switch branches withour losing your progress. git stash
  2. revert - Let's say you have made a mistake in a previous commit and you need to undo it. You can use git revert to create a new commit that undoes the changes introduced by the previous commit. You can do this with commit hash, or using HEAD~n..HEAD, where n is the number of commits before HEAD. git revert HEAD~n..HEAD
  3. add . - add all tracked(modified/deleted) files
  4. add -u - add all tracked(modified/deleted) + untracked(added/modified) files
  5. add -A - add all tracked(modified/deleted) + untracked(added/modified) files + staged
  6. log - Shows the public commit history of your repository. git log
  7. reflog - Focuses on the history of branch and HEAD movements. Acts like an undo log for your local repository. git reflog

Git workflow

  1. Create a new branch git checkout -b branch-name
  2. Check status git status
  3. Add changes git add .
  4. Add commit/save changes git commit -m "message"
  5. Upload all changes to github git push -u origin branch-name
  6. Bring any changes from main to branch-name, to not have conflicts (good habit) git pull origin main
  7. Open pull request on github, if everything is ok delete branch
  8. git checkout main
  9. Get all the changes into main from github repo git pull
  10. Delete branch git branch -D branch-name from local not github

git's People

Contributors

alexb017 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.