Skip to content

Instantly share code, notes, and snippets.

@AdrianBinDC
Created June 20, 2021 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdrianBinDC/828e86a31ede56f22fa9cf994ca3e6e3 to your computer and use it in GitHub Desktop.
Save AdrianBinDC/828e86a31ede56f22fa9cf994ca3e6e3 to your computer and use it in GitHub Desktop.

Git Tutorial

Create a new repo

In the root directory of the project you want to have version control, type the following:

git init

This is a one time thing. After you initialize the repo, you won't have to do it again.

Create a branch

When adding new functionality, create a branch with the following command:

git checkout -b your-branch-name

This will create a branch off master or main that you can work on.

Saving your work

Once you're ready to commit work to the branch, type the following:

git commit -m "a short commit message here re: what was done"

Merging your work

Once you're done implementing functionalty on your branch, you're ready to merge it into master or main. You do that as follows:

  1. git checkout master or git checkout main, depending upon what your root level branch is called.
  2. git merge your-branch-name

The first command checks out master. The second command merges your-branch-name into master.

Figuring out which branch you're on

To figure out which branches you have, you can type the following commands:

git branch

To exit out of the branch list, just type q for quit

Deleting branches

To delete a branch, type the following:

git checkout -d your-branch-name

Cherry Picking Commits

All commits have a hash mark assigned to them. To get a list of commits, type the following:

git log

Typeing that out will give you a list that looks something like this:

commit ecefc1d0bfda09b0c00fbe7f243f27692ce7ccd3 (HEAD -> wValidator)
Author: AdrianBinDC <adrian.bolinger@me.com>
Date:   Fri Jun 18 20:59:13 2021 -0400

    Updated team acronym

commit adcd77af73473cb4d40c46c4105b3a518b6654ab
Author: AdrianBinDC <adrian.bolinger@me.com>
Date:   Fri Jun 18 20:57:55 2021 -0400

    Added new maintainer to README.md

commit 3574ab377c371cb73dd16397f73e776354cb5af7
Author: Will <will@example.com>
Date:   Mon Jul 3 16:28:46 2017 +0700

    Whoops—didn't need to call that one twice

commit 43d6f24d140fa63721bd67fb3ad3aafa8232ca97
Author: Will <will@example.com>
Date:   Mon Jul 3 16:24:13 2017 +0700

    check05: Finally, we can return true

commit bf3753e4c693f45610f06084587b0c1631df9ac9
Author: Will <will@example.com>
Date:   Mon Jul 3 16:23:47 2017 +0700

The commit <commit hash with a bunch of jibberish> message tells you what the commit hash is. To get a particular commit and put it on another branch, you can just get the commit hash, go to your branch (git checkout branch-you-want-to-be-on) and type:

git cherry-pick ecefc1d0bfda09b0c00fbe7f243f27692ce7ccd3.

Conclusion

This should be enough for you to get the basics of git. As you progress or run into issues, you can Google them to fill in the blanks.

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