Evgenii Vedegisthoughts about software development

GIT Cheat sheets complete list for super quick start

Date published: January 04, 2021

GIT Cheat sheets Quick reference guides

GIT Cheat sheets Quick reference guides for super quick start. This is my complete list of commands what really use. It's really useful for beginners even intermediate!

Open command line Using cd command, go to the project directory we need:

CommandDescription
$ git statusshows status of files
$ git initinitializes git repository (creates a .git subdirectory)
$ git add example.jsadds (indexes) example.js file for next commit
$ git add.adds all files to index.
$ git add -uadds all modified files to index.
$ git commit -m “first commit”commits changes with a comment in quotes ( -m option indicates of comment)
$ git commit -a -m “added new”'-a' option forces Git to automatically index every file already tracked at time of commit. allowing you to do without git add
$ git reset - path / file.cppremoves path / file.cpp from index.
$ git rm —cached example.jsremoves example.js file from index without deleting it in working directory
$ git rm -r —cached testremoves test directory (recursively) from index without deleting it in working directory

GIT Remote repositories commands

Each remote repository has a URL and a short name for get info, clone etc

CommandDescription
$ git remoteshow short names (memes) of remote repositories
$ git remote -vshow short names (memes) of remote repositories and their corresponding URLs
$ git remote show ogshow information about remote og repository
$ git remote add og urladd a new remote repository at url, which is given short name og. This will allow you to later refer to the remote repository by name (instead of url)
$ git clone urlclone repository from specified url
$ git clone url asdclone repository from specified url and renames to asd
$ git push og devsubmits dev branch to remote repository og (og is either full path to the remote repository or its shorthand meme). This command only works if you cloned from a server where you have write permissions and if no one else has performed push command since then. If you and someone else are cloning at the same time, then they push command, and then you push command, then your push will definitely be rejected. You will have to pull their changes first and merge them with yours. Only then will you be allowed to push.
$ git push -u og devsubmits dev branch to remote og server and links local dev branch and dev branch in remote repository. That is, after such a command (which is executed once), it will be possible to send / receive changes only by performing git push from the branch without specifying any aliases for server and remote branches.
$ git fetch ogretrieves from remote og repository all changes that are not in your local repository, but does not merge them into your work and does not modify what you are currently working on. You will need to manually merge this data with yours when you're ready with merge command.
$ git push og —delete serremoves ser branch on og server. Pointer is deleted on the server. Git server will leave data until garbage collector starts. That is, if a branch is accidentally deleted, it is often easy to restore it.
$ git remote rename kt evgeniirenames remote kt repository to evgenii
$ git remote rm paulremoves a link to a remote repository. This is necessary, for example, if you have changed server or are no longer using a certain mirror or perhaps contributor has ceased to be active

GIT branch commands

Almost every version control system (VCS) supports branching. Let's see how it's works in git with Cheat sheets:

CommandDescription
$ git branchlists available branches (indicate branch that HEAD points to, ie branch you are currently on)
$ git branch devcreates a branch named dev (but doesn't switch you to it!)
$ git branch -d devremoves branch named dev
$ git checkout devswitch to branch dev
$ git checkout -b devcreates dev branch and switches to it immediately
$ git branch -vshows last commit in each branch
$ git branch -m old newrenames local branch from old to new

GIT Merge commands

Note: Before merging branches, you need to use command $ git checkout <name_branch> to go to the branch which will be merge

CommandDescription
$ git merge devmerges dev branch into current branch
$ git mergetoolopens a graphical conflict resolution tool
$ git branch —mergedshows list of branches you have already merged with current one. Those branches from this list that do not have a * before them can be safely deleted with command git branch -d; work from these branches is already included in another branch, so nothing gets lost.
$ git branch —no-mergedshows list of branches containing work that you have not yet merged into current branch. These branches cannot be deleted with git branch -d

Check this article for learning git faster with gaming!

More links:


© Copyright 2021, Evgenii Vedegis