Skip to content

Instantly share code, notes, and snippets.

@albatrocity
Created September 7, 2011 17:28
Show Gist options
  • Save albatrocity/1201187 to your computer and use it in GitHub Desktop.
Save albatrocity/1201187 to your computer and use it in GitHub Desktop.
Some basic Git instructions for Github for Mac and the command line

Using Git version control for code projects

Creating a new code repo from a local working copy

  1. From the repositories view in the app, drag the project folder to the bottom of the left sidebar.
  2. Hit "Yes" when it asks if you want to create a local git repository
  3. Go to "Changes" view (⌘2)
  4. Select the files that you want to commit their current state to the repository. You can view the changes of the file by clicking on the double up arrow on the file name bar.
  5. Type a commit summary, usually a description of what you've just added or changed.
  6. Click 'Commit'. This commits the current state of the code to your local repository. Do this every time to do something significant like fix a bug or develop a feature. Commit early and often. Each state of code is available to you at any time via the History view (⌘1).

with the command line

  • Open Terminal.app
  • "cd" to directory
cd path/to/directory
  • Initiate a git repository
git init .
  • Add existing files
git add .
  • Commit all files (-a) and add a message (-m)
git commit -a -m "commit message goes here"

Cloning (checking out) someone else's repository

  • Visit the repo on Github.com and click the "clone to Mac" button, or...
  • Select the repo in the Repositories list within the app, under the cremalab account.

with the command line

  • "cd" to desired directory
  • clone the repo with the clone url
git clone git@github.com:albatrocity/gratuitator.git

Syncing repository branches with a remote repository

  1. Make sure you have committed the current state of your code
  2. Drill into your repo in the app and click Sync Branch in the upper right corner. This pulls down the latest code from the remote repository, merges your code with it, and pushes your changes to the remote repository.

If you only want to get the latest code from the remote repo, select Repository > Pull (⇧⌘P) from the menu bar. This merges the remote code with your local code but does not push up your changes.

If you only want to push up your current state to the remote reop, select Repository > Push (⌘P). This will only work if you already have the most up to date code from the repo.

with the command line

  • Make sure you have committed your current state.
  • Get the most up to date code from the remote repo
git pull origin master
  • Push your local code to the remote repo
git push origin master
@sdjobapps
Copy link

Wonderful directions

@Tabicat44
Copy link

Thank you!!!! <3

@lxgzxyy
Copy link

lxgzxyy commented Sep 13, 2020

THANK YOU!

@wasifkhan1998
Copy link

if through git add . git not added to the file then what should be done?

Copy link

ghost commented Mar 31, 2021

How would I login?

@shashankrustagi
Copy link

There is no tracking information on pull

@aamnacodes13
Copy link

git push origin master is not working for me. Can someone help me?

@joshorrom
Copy link

@aamnakhan2002 Github by default uses "main" and not "master" now (pretty sure this is new)

You will need to use a PAT (Personal Access Token) as your password when signing in from terminal, find more info here: https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls

and it only required me to use it once then keychain saved the PAT and I haven't needed to enter a user and password when pushing/pulling from repo again.

@AmirTanirbergenov
Copy link

I didn't understand

@vikash-mdh
Copy link

i dont 't understand this code

@KaliShanker
Copy link

trying to use atom as my editor, but keep getting the error "zsh: command not found: Atom". I tried
git config --global core.editor "Atom"
but had no luck getting atom to open a file.
any help with this would be so appreciated!!

@kashandomore
Copy link

git push origin master is not working for me. Can someone help me?

@jnnbllclvcll
Copy link

Thank you! This works on my Mac. I am working with someone using Microsoft so the request or pull origin must be master not main. Such a big help!

@maianhtuant
Copy link

Thank you so much :)

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