Git: Difference between revisions
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
== Test == | == Test == | ||
<syntaxhighlight lang="cpp" style="border: 3px dashed blue; background-color:#011627;"> | <syntaxhighlight lang="cpp" style="border: 3px dashed blue; background-color:#011627;"> | ||
int main(int a, char* args[]) { | int main(int a, char* args[]) { | ||
Line 9: | Line 8: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Getting stuff from other branch == | == Getting stuff from other branch == |
Revision as of 01:11, 21 September 2024
Helpful commands
Test
int main(int a, char* args[]) {
// Test
return 0;
}
Getting stuff from other branch
git remote add live <other branch>
git pull live master
Commit
git commit -m "This is a great check in"
git push
Checking out a branch
git clone <address>
git fetch origin
git checkout <branch name>
Setting Credentials
git config --global credential.helper store
Show non pushed changes
git diff origin/master..HEAD
Put a cloned project into gitlab
git init
git remote set-url origin http://gitlab.com/bibble235/project.git
git commit -m "copy of project"
git push
Compare Branches
$ git diff branch1..branch2
Show Which Branch
git branch
Merging
This is how to merge from main to mybranch
// clone the source
git clone blahhhh
// checkout the branch
git checkout mybranch
// merge changes into main
git merge main
// Go into vs code
// Take the version you care about
git commit -m 'Merge code to main'
git push
View Deleted Files
# List all deleted files
git log --diff-filter D --pretty="format:" --name-only
# Find last commit
git log -n 1 --pretty=format:%H -- src/services/__test__/myFile.test.tsx
Setting up new Repo from CLI
cd /path/to/repo
# Make sure you need this line, maybe you did it wrong the first time
rm -rf .git
git init
git branch -m main
git remote add origin https://gitlab.com/<user>/<repo_name>
git add .
git commit -m "first commit"
git push -u origin main
Making a Branch for Change
git branch 123xx
git checkout 123xx
git add .
git commit -m "Blah"
git push
# Make a pull request
# If request rejected you can reset what you have
git reset ^HEAD
# Recommit your stuff
git add .
git commit -m "Blah"
git push
July 2023
Update local Main Branch (main) to remote (main) branch
// Make sure you have not modified this prior to starting (unless you wanted to)
// In the local copy directory
git pull origin main
// Check all good git diff should be empty (unless you have made changes)
git diff
Update local non-Main Branch (DEV) from remote (main) branch
This is the way I currently do it
git fetch origin main
git merge origin/main