Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Git Bootcamp

Local Setup

Installation and configuration

First, check if git is installed on your machine by running the following command.

$ git --version
git version 2.42.0

Now add your email and name to the git config:

$ git config --global user.email jwood@example.com
$ git config --global user.name 'Josh Wood'

The git dag command is more user friendly than the original git log command. Add it by running

$ git config --global alias.dag "log --graph --abbrev-commit --decorate --format=format:'%C(blue)%h%C(reset) - %C(cyan)%aD%C(reset) %C(green)(%ar)%C(reset)%C(yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(white)- %an%C(reset)' --all"

Making your first commit

Then cd into the root directory of your project. For instance, if my project folder is git-bootcamp, I would do

$ cd <SOME_PATH>/git-bootcamp

Now, initialize your local git repository on the branch main by running

$ git init -b "main"
Initialized empty Git repository in <SOME_PATH>/git-bootcamp/.git

Note that there are files you do not want git to track. For instance, the object files (.o) and binary runnable generated by the compiler. You should put things you do not want git to track in a .gitignore file in the project root directory. Run touch .gitignore in the project root directory and edit it using your favorite editor.

There is one utility I found useful for this purpose. Go to https://gitignore.io and create useful .gitignore files based on the language/framework you use. The following link shows the .gitignore file for a project written in C and Python. https://www.toptal.com/developers/gitignore/api/python,c. You are always free to add more project specific files/folders based on your need.

Once you are ready, you can run the following commands to make your first commit:

$ git add -A
$ git commit -s -m "initial commit"

Great! Congratulations on your first commit!

Track your repository on GitHub

Git vs. GitHub

Now we are going to push your commits to GitHub. First, note that git is a version control system that lets you manage and keep track of your source code history, while GitHub is a cloud-based hosting service that lets you manage Git repositories. Thus, it is totally possible to only use git locally without even touching GitHub. There are many benefits of using GitHub, things include:

  • backup files from local drive
  • enable collaboration between teammates
  • share code with rest of open-source community
  • better UI
  • better issue tracking and CI/CD

GitHub Setup

To get started, make sure you have a GitHub account. Once you logged in, we want create a personal access token for authentication purposes. Please follow the instructions on this page to generate your personal access token. Once your token is generated, you should store it somewhere because you won't be able to see it again. To setup credential caching, you can do the following:

$ git config --global credential.helper store

Alternatively, see here for instructions on all platforms.

Create a new remote repository

Go to https://github.com/new to create a new repository by following the instructions.

Note: Since we already have a repository locally, do not add README, license, or .gitignore files. If you don't want to or cannot (for academic reason) share the code with public, make sure you select the "Private" option for the visibility.

Then follow the instructions on the redirected page to link your local repository with the one on GitHub. In our case, we run

$ git remote add origin https://github.com/<github_username>/<project_name>.git
$ git branch -M main
$ git push -u origin main

You might see the GitHub ask you for your username and password. You should use your personal access token in the keyword field. After you enter your credentials once, the credential caching should work and you won't need to retype the token again.

Username: YOUR_GITHUB_USERNAME
Password: YOUR_PERSONAL_ACCESS_TOKEN

Now go to https://github.com/<github_username>/<project_name>.git, you would see your changes appear in the remote repository. Congrats, you have setup your project on GitHub!

About

A walkthrough of basic Git setup and workflows

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors