Git Commandline #
# Check Git Version
git --version
Note: The branch former called “main” is now called “master” branch.
Clone Repository #
# Clone Repository
git clone ...
# CD into Repository
cd repository
Change Branch #
# Fetch the latest branch information from the remote repository
git fetch
# List all available branches, including the remote branches
git branch -a
# Switch (local) branch
git checkout master
# Verify current branch
git branch
# Create and check out a new local branch that tracks the remote branch using the following command:
git checkout -b local-branchname origin/remote-branchname
Add, Commit & Push #
# Open file in Visual Studio Code (Save file / changes)
code .\filename
# Check the status of your changes using the following command:
git status
# Add Changes: All changes in current directory)
git add .
# Add Changes: Specific file
git add new-file.md
# Commit Changes
git commit -m "Made some changes"
# Push the commits from local branch to the remote repository: Default remote repository
git push
# Push the commits from local branch to the remote repository: Define remote repository
git push origin remote-branchname
Pull #
# Pull latest changes from Remote Repository
git pull origin master
Change Commit Message #
# Change Commit Text
git rebase -i HEAD~1
- Change “pick” to “reword”
- Save & close the commit message editor
- Git will prompt you to edit the commit message
- Save & close the commit message editor
# To list all commits in a Git repository
git log
Init new local Project #
# Create new Project in GitLab Webinterface
https://gitlab.com/jueklug/my-repository
# Create Folder for Repository
mkdir my-repository
# CD into Folder
cd my-repository
# Initialize Git Repository
git init
# Connect your local repository to the remote repository (SSH)
git remote add origin git@gitlab.com:jueklug/my-repository.git
Optional: Add something to push
# Create file
touch readme.md
# Add specific Changes
git add readme.md
# Commit Changes
git commit -m "Made some changes"
Push
# First time push
# Associate your local master branch with the master branch on the origin remote
git push -u origin master
# Push Commits to Remote Repository
git push origin master
Line Ending Conversion #
# List Git automatic line ending conversion status
git config --get core.autocrlf
# Set Git automatic line ending conversion: Off
git config --global core.autocrlf false