- Version
- Download 136
- File Size 58.00 KB
- File Count 1
- Create Date February 14, 2024
- Last Updated February 14, 2024
Git commands
1 | git -v |
Show the version of your Git installation |
---|---|---|
2 | git config -l |
Show the configurations |
3 | git config --global user.name "Thomas Claudius Huber" git config --global user.email "[email protected]" |
Configure your username and email. The username and email is used by Git for every commit that you will create. Without this configuration, you are not able to commit to a repository. |
4 | git config -l --show-origin |
To show the origin of the configurations, you learned about the --show-origin parameter. It shows you in which file a configuration is located. This command above allows you to find the .gitconfig file that is in your user directory. That .gitconfig file contains now the username and the email that you configured. |
Working with Local Repositories | ||
5 | git init |
Initialize an empty Git repository |
6 | git status |
Show the status of your repository |
7 | git add readme.txt |
Stage a specific file |
8 | git add . |
Stage all changed files |
9 | git commit -m "Create readme file" |
Commit the staged files |
10 | git config --global core.editor notepad |
Define notepad as an editor. It will be used when you run the git commit command without -m parameter |
11 | git diff readme.txt |
Show the changes of a specific file |
12 | git diff |
Show the changes in your working directory |
13 | git diff --staged |
Show the changes in your staging area |
14 | git log |
Show the history/log |
15 | git log --pretty=oneline |
Show the history/log with one commit per line |
16 | git checkout b346471 |
Checkout a specific commit by its snapshot hash |
17 | git checkout main |
Navigate back to your main branch |
Branching and Merging Code | ||
18 | git branch |
List the local branches |
19 | git branch feature/AddTwitterHandle |
Create a new branch with the name "feature/AddTwitterHandle" |
20 | git checkout feature/AddTwitterHandle |
Checkout the new branch |
21 | git checkout main |
Checkout the main branch |
22 | git merge feature/AddTwitterHandle |
Merge changes from the feature branch into the main branch. This command assumes that you have the main branch checked out |
23 | git log --pretty=oneline --graph |
Show a graph when showing the history |
Pushing to a Remote Repository | ||
24 | git remote add origin https://repositoryURL |
Add the remote repository https://repositoryURL under the name origin to your local repository |
25 | git push -u origin main |
Push the first time to the main branch of the remote repository and set it as upstream |
26 | git push |
Push the next commits to the remote repository |
27 | git clone https://repositoryURL |
Clone a remote repository with the URL https://repositoryURL into a local repository on your machine |
28 | git clone https://repositoryURL . |
Clone a remote repository into the current directory (Note the separate dot at the end that indicates the current directory) |
28 | git fetch |
Fetch changes from the remote repository without merging them into your local branch |
Download