Advanced Flashcards
Git Set Up
- Set a Git username.
- Confirm that you have set the Git username correctly.
git config –global user.name “Mona Lisa”
git config –global user.name
Git Set Up (2)
- Set an email address in Git.
- Confirm that you have set the email address correctly in Git.
- Change the email associated with commits you make in a single repository. Overriding global Git config settings in this one repository, but won’t affect any other repositories.
git config –global user.email “example@gmail.com”
git config –global user.email
git config user.email “new_example@gmail.com”
Generate a new SSH key for Git with Git Bash.
ssh-keygen -t rsa -b 4096 -C “your_email@gmail.com”
Add your SSH key to the ssh-agent with Git Bash.
- Ensure the ssh-agent is running.
- Add your SSH private key to the ssh-agent.
- Copy the SSH key to your clipboard.
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
clip < ~/.ssh/id_rsa.pub
Initialize a Git repository.
- Make a new directory to practice and enter it.
- Turn the current, empty directory into a fresh Git repository.
- Create a new README file with some sample text.
- Add the new file to the Git staging area.
- Make your first commit with the new README file.
- mkdir git_practice & cd git_practice
- git init
- echo “Hello Git and GitHub”»_space; README.txt
- git add README.txt
- git commit -m “First commit”
Add your local repository to the remote GitHub repository.
And push the first commit.
git remote add origin git@github.com:/git_practice.git
git push -u origin master
- Delete the most recent commit, keeping the work you’ve done:
- Delete the most recent commit, destroying the work you’ve done:
1.
git reset –soft HEAD~1
2.
git reset –hard HEAD~1
In order to get your own replica of a remote GIT site, clone this site to a local location.
git clone remote_location clone_name
- remote_location tells Git where to go to find the remote. This could be a web address or a filepath.
- clone_name is the name you give to the new directory in which Git will clone the repository.
Enter in terminal the command to list the remotes - the name of the remote, origin, as well as its location.
*You must cd in the corresponding directory.
git remote -v
*Git automatically names this remote origin, because it refers to the remote repository of origin. However, it is possible to safely change its name.
Check if changes have been made to the remote and bring the changes down to your local copy.
git fetch
*This command will not merge changes from the remote into your local repository. It brings those changes onto what’s called a remote branch.
Switch to your master branch and merge with origin/master, - the remote site where the most recent commits are.
git checkout master
git merge origin/master
Push your new branch up to the remote, origin, where it can be reviewed and merged into the master branch, making it part of the definitive project version.
git push origin YOUR_NEW_BRANCH
Define the Git Collaborative Workflow for working with a remote branch.
Git Collaborative Workflow:
After the origin/master has been merged into the local master branch, the local branch is ready to be worked on. The workflow for Git collaborations typically follows this order:
- Fetch and merge changes from the remote
- Create a branch to work on a new project feature
- Develop the feature on your branch and commit your work
- Fetch and merge from the remote again (in case new commits were made while you were working)
- Push your branch up to the remote for review
* Steps 1 and 4 are a safeguard against merge conflicts, which occur when two branches contain file changes that cannot be merged with the git merge command.