Using Git - ktopolov/DatabaseSystem GitHub Wiki

Basic Commands

Git can seem complicated, but most of the commands are fairly basic and will become repetitive over time.
Setup Repo/Branch

  • git clone <repository_address>: Clone contents of a remote repository to local machine.
    • On GitHub, a repository always shows a green button that says Clone. Copy the link (the SSH link) and then past this in the <repository_address> spot.
  • git branch: See all available branches and see the current working branch. Default shows local branches only. Run with git branch -a to see local and remote branches; -r shows remote only. Use git branch -d <branch_name> to delete a local branch; for example, after merged
  • git fetch: If you have not cloned recently, new branches may be added/deleted from the repository. Use fetch to update Git's knowledge about which branches exist
  • git checkout branch_name: If checking out a remote branch, do NOT include the remote/ in front of the name.
  • git pull: Pull any changes from remote repository to local branch

Commmit Workflow To commit and push changes to remote repo, here are some useful steps:

  • 'git branch' # verify you are on proper branch
  • git status # check which files have been added/removed/modified since last commit
  • git add -A or git add <filename1> <filename2> ... to add files to stage
  • `git commit -m "Message here" # commit branch
  • git pull # optional; ensures any changes on remote repo pulled to your local before you push up. Will initiate local merge if any conflicts
  • git push # push local files to remote branch

gitignore

If you do not want Git to try to version control some files in your repo (because they are too large or some other reason), you can:

  • Create a .gitignore at the top level of your repo. In this file we can:
    • Explicitly list any files we don't want to track
    • List a folder for which all files underneath should not be tracked
      For example:
# Do not version single file /src/main.cpp
/src/main.cpp

# Do not version any file beneath the top-level /build folder
#   Note: if a /build folder shows up at a sub-level, it will be versioned unless you use */build
/build
⚠️ **GitHub.com Fallback** ⚠️