Contents
Introduction
This module takes a look at Git commands. By practicing these commands, you will be able to better understand the essential Git concepts so that you can maximize your productivity with Git/GitHub. You will execute Git Commands from a bash shell.
Prerequisites
- After setting up your Squirrel environment, you should have already updated the IntelliJ terminal to utilize the bash shell. For instructions on how to do this, consult the Change IntelliJ Terminal section of Setting Up Squirrel in IntelliJ for assistance.
Git Configuration
Use the
command to work with your settings stored as follows:
Git stores and sets configurations at various levels (each subsequent level overrides the previous level):
Level | Location | Contents | Command to set scope |
System | /etc/gitconfig | Configurations for every user and all repositories |
|
User | ~/.gitconfig | Configurations specific to user |
|
Repository | .git/config | Configuration specific to that single repository |
|
Verify that user.name and user.email have been set in your global configuration by IntelliJ by executing the following command in your terminal:
class="highlight">
1
| 1
| git config --global user.name <Name> |
and
1
| git config --global user.email <email> |
to set them if they haven't been set:
class="highlight">
or
Create a Repository
-
Go to your GitHub page: https://github.com/yourUserName
-
Go to the Repositories tab
-
Click on the new button and provide the basic information:
TODO: MM I think something is missing hereā¦there isn't any command listed
Clone
Use 1
| git clone https://github.com/yourUserName/yourRepository |
to clone a copy of the repository onto your local machine
class="highlight">
1
| 1
| git remote add origin https://github.com/yourUserName/yourRepository |
To create an 'upstream' link, use 1
| git remote add upstream https://github.com/yourUserName/yourRepository |
class="highlight">
1
2
| class="highlight">1
2
| class="highlight">1
2
| class="highlight"> command, we can see the files that have been modified, but are not staged for commit: Stage a modified file with the command class="highlight"> 1
2
| 1
| git commit -m "message text" <filename> |
command class="highlight">
that your branch is now one commit ahead of origin (remember that the commit command only moves files from the Staging Area to the .git Directory, it does NOT have any affect on the repositories living in GitHub). If you don't see any benefit from using the staging step, you can combine add and commit steps with . class="highlight"> Another alternative for altering the history of a bad commit is amend. class="highlight"> 1
| class="highlight"> to import commits from a remote repository into your local repo. These commits are stored as remote branches, giving you the opportunity to review changes before integrating them into your copy of the projects. class="highlight">
to merge these changes into your local repository. class="highlight"> 1
| 1
| git pull <remote> <branch> |
command class="highlight"> 1
| 1
| git checkout -b <new-branch> |
creates a new branch with the name you specify and makes that branch the current branch. In the following example, we are creating new branch called "myfeature" and modifying a file (junk) within that branch. Then, we are committing that change with a message of "test2" class="highlight"> 1
2
3
| 1
| git branch -d <branch-name> |
deletes the specified branch name In the following example, we are deleting a branch called "myfeature" class="highlight"> 1
| 1
| git checkout <existing-branch> |
to switch to a specified branch. In the example below, we are switching to the "master" branch and merging changes from the "myfeature" branch. As always, we can get the status of our repositories with to verify changes. class="highlight"> 1
2
3
| class="highlight">1
2
3
| class="highlight">1
2
3
4
5
| class="highlight">1
2
| class="highlight">1
| 1
| git update-index --assume-unchanged <file> |
class="highlight"> 1
| 1
| git update-index --no-assume-unchanged <file> |
|
|
|
|
|
|
|
|