Skip to content

Instantly share code, notes, and snippets.

@CitizenOfRome
Last active February 11, 2020 11:32
Show Gist options
  • Save CitizenOfRome/3e16680212588dc2906e595d8d1d26bc to your computer and use it in GitHub Desktop.
Save CitizenOfRome/3e16680212588dc2906e595d8d1d26bc to your computer and use it in GitHub Desktop.
Getting started with Git

Please install the command-line GIT tool from https://git-scm.com/ and run ssh-keygen in the newly setup git commandline tool / git-bash

Here are a few commands you'll be using often to interact with git, as a quick reference, keep them handy somewhere so that you can quickly get used to them:

  1. Run git config --global core.longpaths true after installing git to enable support for longpaths on windows which we use for some repos with legacy dependecies.

  2. git clone https://[email protected]/team/project.git - Downloads a copy of the website code for local use (Used only the first time).

  3. git add . -A && git commit -am "Your commit Message describing the changes you made" - Once you make changes, you can have git record them with this command; Make sure you add and commit for every significant change, so that you also have an additional backup

  4. git push -u origin master - Uploads your code the the central git repository for the rest of the team to use. Make sure you push often and that you push once you're done with the changes on a given session

  5. git pull - Updates your local copy of the code with the latest changes made by the rest of the team on the central git repository. Always make sure to do a pull before you start a coding session and before you push.

  6. git init - Initializes a git repository in the current folder

  7. git checkout -b branch_name - forks the current code into a new branch named branch_name

  8. git diff --name-only --diff-filter=U to list files with merge conflicts (Unmerged (U) files)

  9. git rm -r --cached . remove all 'added' files from tracking (useful when you add a new exception to .gitignore)

  10. git add . -A && git fetch && git reset --hard FETCH_HEAD for a hard reset

Do make sure to read the messages that git shows you when you do anything and watch out for the cases where an error occurs. Some common interruptions you're likely to see:

  1. A merge conflict - This happens when git cannot figure out how to add the latest code from the central repo to your changes when you pull, when this happens, read the message and make a note of the files that have conflicts, then edit them one after another, look for the "HEAD" keyword and remove the code that doesn't fit; basically, manually replace the conflicted section with a working piece of code that also holds the changes that the rest of the team made. See: http://githowto.com/resolving_conflicts and https://help.github.com/articles/resolving-a-merge-conflict-from-the-command-line/

  2. A git setup/configuration issue - Git may ask you to run a few config commands when required, just carefully read the message, google it and take appropriate action. One example is with the default push configuration, where git may ask you to set it up and suggest that you run git config --global push.default simple, you can do so safely.

Hope this helps you get started with with git, which as you'll see will prove to be absolutely vital when working with a distributed team like ours, and once you get the hang of it, it'll become something that you'll never code without.

https://try.github.io/levels/1/challenges/1 may also help you get up to speed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment