Skip to content

πŸ“š The ultimate collection of git commands and resources to power up your programming!

Notifications You must be signed in to change notification settings

GoldinGuy/UltimateGitResource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

73 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UltimateGitResource

πŸ“š A list of helpful Git commands for the Google DSC Git Event & Hackapalooza Hackathon

Discuss On Discord Contributors Issues

Watch a recording of the All About Git presentation here!

Git is the most popular version control system. It tracks changes you make to files and keeps a record of your work. It also lets you revert to earlier versions of your code if the need arises. Git drastically improves collaboration, allowing multiple people to work in sync on the same source code. Below is a selection of the most helpful and commonly used Git commands to power up your programming!

Note - Wherever used the shorthand Repo means Repository

The Docs folder of this repo contains a simple profile/resume static site built on HTML5 and TailwindCSS to help learn about Github pages. You can clone the repository and test it out yourself, or visit this link to see a live demo. For more info look at the README for the /docs directory.

This repo contains a powerpoint presentation explaning many of these commands that can be viewed online here.

Table of Contents

Git Commands

You can run git help in the terminal to learn about many of these commands at any time. git help -a and git help -g list available subcommands and concept guides. git help <command> or git help <concept> allow you to read about a specific subcommand or concept.

HEAD represents your current working directory. The HEAD pointer can be moved to different branches, tags, or commits using git checkout.

The gitignore file allows you to control what gets committed and what doesn't, allowing you to keep your keys and passwords secure, and reducing the amount of bloat on the remote repo. You can learn more about it in the .gitignore file above.

πŸ“— Gitting Existing Projects

Command Description
git clone ssh://git@github.com/<username>/<repository-name>.git Create a local copy of a remote repo using SSH
git clone https://github.com/<username>/<repository-name>.git Create a local copy of a remote repo using HTTPS

You can also fork repos (create a copy of the original repo that remains on your GitHub account).

πŸ“˜ Gitting Started - Setting Up a New Repo

Command Description
git init Initialize a local Git repository
git add . Add all files in the working directory to the staging area
git commit -m "<commit message>" Commit your changes
git remote add origin git@github.com:<username>/<repository-name>.git Add upstream repo to publish commits at (the remote repo)
git push -u origin master Push your changes to remote repository

More Options For Staging Files

Command Description
git add <file-name.txt> Add a single file to the staging area
git add -A Add all files in all directories to the staging area
git rm -r <file-name.txt> Remove a single file (or folder)
git rm -r . --cached Remove all files recursively from staging area

πŸ“™ The Nitty Gitty - Examine History & State

Command Description
git status See details about the current branch
git show Shows changes in committed files
git log View changes in commit history
git log --summary View changes (detailed)
git log --oneline View changes (briefly)
git diff <source branch> <target branch> Preview changes before merging

πŸ“’ Branching Out - Grow, Mark & Tweak History

Command Description
git branch List branches (the * is the current branch)
git branch -a List all branches (local and remote)
git branch <branch name> Create a new local branch
git branch -d <branch name> Delete a local branch
git push origin --delete <branch name> Delete a remote branch
git checkout -b <branch name> Create a new local branch and switch to it
git checkout -b <branch name> origin/<branch name> Clone a remote branch and switch to it
git branch -m <old branch name> <new branch name> Rename a local branch
git checkout <branch name> Switch to a branch
git checkout - Switch to the most recent branch
git checkout -- <file-name.txt> Revert your recent changes to a file

πŸ“• Git Gud - Dealing With Merge Conflicts

Command Description
git merge <branch name> Merge a branch into the active branch
git merge <source branch> <target branch> Merge a branch into a target branch
git merge --abort Abort the current conflict resolution process, and attempt to reconstruct the pre-merge state
git stash Stash changes in a dirty working directory
git stash clear Remove all stashed entries

πŸ““ Git More - Pushing, Pulling, & Remote Origin

Command Description
git push origin <branch name> Push a branch to your remote repo
git push -u origin <branch name> Push changes to remote repo (and remember the branch)
git push Push changes to remote repo (only if you have previously set a remote origin)
git push origin --delete <branch name> Delete a remote branch
git pull Synchronize local repo with remote repo
git pull origin <branch name> Pull changes from remote repo
git fetch Checks to see if there are any changes on the remote repo (does not pull changes)
git fetch --prune Fetch all remote branch refs and delete those no longer in use
git remote -v Shows URLs of remote repositories when listing your current remote connections
git remote add origin ssh://git@github.com/<username>/<repository-name>.git Add upstream repo to publish commits at (the remote repo)
git remote set-url origin ssh://git@github.com/<username>/<repository-name>.git Set a repo's origin branch to SSH

πŸ“” Gitting Complicated - The Danger Zone

HEY! Changing your history may cause undesired side effects. You may lose data. Many of these commands cannot be undone. If you change your remote history, don't say I didn't warn you.

Command Description
git rebase <branch> Reapply commits on top of another base tip
git rebase -i <commitID> Reapply all commits from <commitID forward
git cherry-pick <commitID> Apply the changes introduced by some existing commits
git clean -f Removes and deletes untracked files from the working tree
git clean -fd Remove all untracked directories
git commit --amend Allows you to edit a previous commit that has not been pushed
git commit --fixup <commitID> Combine new changes with an existing commit under the same name
git reset <commitID> Reverts all commits after specified commit, while keeping local changes
git reset --hard <commitID> Reverts all history and changes back to the given commit
git reset HEAD~1 Revert 1 commit (while keeping current local state)
git push origin <branch> --force Deletes all your previous commits and pushes your current one

πŸ“– More Git Resources

Contributing

  1. Fork UltimateGitResource here
  2. Create a branch with your improvements (git checkout -b improvement/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin improvement/fooBar)
  5. Create a new Pull Request

Meta

Created by @GoldinGuy for the FAU Google DSC Git Event.