git basics
an intro to git, cli quick-reference guide
Git is a version control system. Used to store, track and manage code and files
I made this guide while studying for reference as I implement git into my workflow.
Intro
git initinitializes the current directory, converting to a git repogit init <repo-name>creates a new git repo with a name
git addadds files/changes to the staging area. OR --alladds all files to the staging area
git commitsaves (or commits) a file to the repo-madds a commit message
git statusshows status of the staging and working areaVersion History
git logview git historygit diffshows differences between commitsgit revertreverts entire repo to a previous commit-nno commit occurs when reverting--no-editno commit message added
git checkoutreverts a single filegit restoreremove file from staging areagit restore --staged <filename>
Branches
git branchlists the current branches*<filename>identifies the current branch
git branch <name>creates a new branch-m <current-name> <new-name>renames a branch-d <name>deletes a branch-D <name>forcibly deletes a branch- delete branches when they are no longer in use.
git switch <branch-name>switches to a branch-ccreates, then switches to the newly created branch
git diffshows differences between branchesMerging
<source-branch>- the branch being merged<destination-branch>the branch being merged into (usually main/master) switch to the<destination-branch>, then run the mergegit merge <source>- avoid editing the same files in multiple branches
Remote
remote repos are stored on a remote server, allows for collaboration between teams
git remote add <remote-name>adds a name for a remote repogit remote -vlists all remotesgit cloneclones a repoget fetch originfetch all remotes fromgit mergemerges from remotegit pullfetches and merges
git pushpush local to remoteCredentials
git credential-cache exitclears current git creds and prompts for new info
Feel free to leave a comment and share any commands you think I should add!
This post is licensed under CC BY 4.0 by the author.
