overview list - most used git commands
Asked Answered
D

4

2

Does anyone has a short list with most used git commands? Not the complete manual, but only what I approximately need daily. I'm new and would like a small list to put under my screen. This to pickup git faster.

That's all folks!

Dunant answered 25/11, 2014 at 8:16 Comment(3)
That would be mainly the porcelain commands (https://mcmap.net/q/12336/-what-does-the-term-quot-porcelain-quot-mean-in-git), listed in schacon.github.io/git/git.html#_high_level_commands_porcelainCutthroat
Thanks VonC. Not verybody likes my question, but I like your answer. I'll make a summary page myself of your link.Dunant
Git 2.5+ (Q2 2015) will propose a more helpful git help. See my answer belowCutthroat
D
2

This is what I came up with. I have printed this out, and it helps me getting started with git commands:

git init
git status
git log --summary

git add file.txt
git add '*.txt'     : add all files, also in subfolders
git rm file.txt     : remove file
git rm -r foldername: remove file and folders recursively

git commit -m "Descriptive text of the change"

git remote add origin https://github.com/try-git/try_git.git
git push -u origin master
git pull origin master
git diff --staged

git add folder/file.txt         : Add file to staged area
git reset folder/file.txt       : Remove file from staged area
git checkout -- folder/file.txt : checkout the last know version, restore.
git branch feature      : create branch
git checkout feature    : use branch (and do the work)
git checkout master     : go back to master before merge
git merge feature       : merge branch into master
git branch -d feature   : delete that branch that is not used any more
Dunant answered 25/11, 2014 at 9:36 Comment(1)
something I seem to be doing all the time: git fetch origin [newbranch]:[newbranch] followed by, after I checkout the branch and try to pull, git branch --set-upstream-to=origin/[newbranch] [newbranch]Critical
C
2

Note: Git 2.5+ (Q2 2015) will present the common Git commands in a more helpful format.

See commit 2241477 by Sébastien Guimmara (Groutcho), 21 May 2015.
(Merged by Junio C Hamano -- gitster -- in commit 6dec263, 01 Jun 2015)
Helped-by: Eric Sunshine

help: respect new common command grouping

'git help' shows common commands in alphabetical order:

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   [...]

without any indication of how commands relate to high-level concepts or each other.

Revise the output to explain their relationship with the typical Git workflow:

  These are common Git commands used in various situations:

  start a working area (see also: git help tutorial)
     clone      Clone a repository into a new directory
     init       Create an empty Git repository or reinitialize [...]

  work on the current change (see also: git help everyday)
     add        Add file contents to the index
     reset      Reset current HEAD to the specified state

  examine the history and state (see also: git help revisions)
     log        Show commit logs
     status     Show the working tree status

     [...]

With Git 2.18 (Q2 2018), the completion allows to customize the completable command list.

By default we show porcelain, external commands and a couple others that are also popular. If you are not happy with this list, you can now customize it a new config variable.

See commit 6532f37 and commit 3301d36 (20 May 2018) by Nguyễn Thái Ngọc Duy (pclouds).

completion: add and use --list-cmds=alias

By providing aliases via --list-cmds=, we could simplify command collection code in the script. We only issue one git command.
Before this patch that is "git config", after it's "git --list-cmds=".
In "git help" completion case we actually reduce one "git" process (for getting guides) but that call was added in this series so it does not really count.

There is a slight (good) change in _git_help() with this patch: before "git help <tab>" shows external commands (as in not part of git) as well as part of $__git_all_commands.
We have finer control over command listing now and can exclude that because we can't provide a man page for external commands anyway.

You now have the new setting:

completion.commands

This is only used by git-completion.bash to add or remove commands from the list of completed commands. Normally only porcelain commands and a few select others are completed.
You can add more commands, separated by space, in this variable.
Prefixing the command with '-' will remove it from the existing list.

Example:

git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
Cutthroat answered 7/6, 2015 at 23:18 Comment(1)
lol git help lists sparse-checkout as a commonly used command... what would really help is a most commonly forgotten commands list, not a most used commandCritical
C
0

I seem to be doing this all the time while synchronizing branches on different computers:

git fetch origin [newbranch]:[newbranch]

followed by, after checking out the branch and trying to pull,

git branch --set-upstream-to=origin/[newbranch] [newbranch]

Critical answered 5/12, 2021 at 9:13 Comment(0)
S
0

-To view branch you working on, globally origin(local machine) and main(github server): git branch

-To make sure all things are up to date before commit changes: git pull origin main

-To upload everything in current project git add . git commit -am "message to commit" git push origin main

You could check all other commands on website https://docs.github.com/en

Seko answered 25/8, 2023 at 7:59 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Shooin

© 2022 - 2024 — McMap. All rights reserved.